SSH command parsing

Source: Internet
Author: User
Tags free ssh rsync

OpenSSH is the free version of the SSH Connection tool. Telnet,rlogin and FTP users may not realize that the passwords they transmit on the Internet are unencrypted, but SSH is encrypted and OpenSSH encrypts all communications (including passwords), effectively eliminating eavesdropping, connection hijacking, and other attacks. In addition, OPENSSH provides secure tunneling capabilities and multiple authentication methods that support all versions of the SSH protocol.

SSH is a great tool and if you want to connect remotely to a server on the Internet, SSH is definitely the best candidate.


1, copy the SSH key to the target host, open password-free SSH login

Ssh-copy-id [email protected]

If you do not have a key yet, use the Ssh-keygen command to generate it.

2. Open the tunnel from the 80 port of a host to the local host 2001 port

Ssh-n-l2001:localhost:80 Somemachine

Now you can enter http://localhost:2001 directly into the browser to access this website.

3. Output your microphone to a remote computer's speakers

DD IF=/DEV/DSP | Ssh-c arcfour-c [email protected] DD OF=/DEV/DSP

This way the sound from your microphone port will be output on the speaker port of the SSH target computer, but unfortunately the sound quality is poor and you will hear a lot of hiss.

4. Compare remote and local files

SSH [email protected] cat/path/to/remotefile | diff/path/to/localfile–

This command works well when comparing local and remote files for differences.

5. Mount the directory/file system via SSH

SSHFS [Email Protected]:/path/to/folder/path/to/mount/point

Download SSHFS from http://fuse.sourceforge.net/sshfs.html, which allows you to mount a directory securely across the network.

6. Establish SSH connection via intermediate host

Ssh-t reachable_host ssh Unreachable_host

Unreachable_host represents a host that cannot be accessed directly from the local network, but can be accessed from the Reachable_host network, which creates a unreachable_host connection through a "hidden" connection to reachable_host.

7. Copy your SSH public key to the remote host and turn on password-free login – a simple way

Ssh-copy-id [email protected]

8. Connect directly to host A that can only be connected via Host B

Ssh-t HostA ssh HostB

Of course, you need to be able to access host a.

9. Create a persistent connection to the target host

SSH-MNF <user>@

Create a persistent connection to the target host in the background, using this command in conjunction with the configuration in your ~/.ssh/config:

Host Hostcontrolpath ~/.ssh/master-%[email Protected]%h:%pcontrolmaster No

All SSH connections to the target host will use persistent SSH sockets, which is useful if you use SSH to synchronize files regularly (using RSYNC/SFTP/CVS/SVN), because a new socket is not created each time an SSH connection is opened.

10. Connect the screen via SSH

Ssh-t Remote_host Screen–r

Connect directly to a remote screen session (saving the useless parent bash process).

11. Port Detection (knocking)

Knock 

On a port to open a port on a service (such as SSH), then tap to close the port, you need to first install KNOCKD, here is a sample configuration file.

[Options]logfile =/var/log/knockd.log[openssh]sequence = 3000,4000,5000seq_timeout = 5command =/sbin/iptables-a INPUT -I eth0-s%ip%-P tcp–dport 22-j accepttcpflags = syn[closessh]sequence = 5000,4000,3000seq_timeout = 5command =/sbin/ iptables-d input-i eth0-s%ip%-P tcp–dport 22-j accepttcpflags = syn

12. Delete a line from a text file, useful fixes

Ssh-keygen-r <the_offending_host>

In this case, it is best to use a professional tool.

13. Run complex remote shell commands via SSH

SSH host-l user $ (<cmd.txt)

More Portable Versions:

SSH host-l user "' Cat cmd.txt '"

14. Copy the MySQL database to the new server via SSH

Mysqldump–add-drop-table–extended-insert–force–log-error=error.log-uuser-ppass OLD_DB_NAME | ssh-c [email protected] "Mysql-uuser-ppass new_db_name"

Dump a MySQL database with a compressed SSH tunnel and pass it as input to the MySQL command, which I think is the fastest and best way to migrate a database to a new server.

15. Remove a line from the text file to fix the "SSH host key Change" warning

Sed-i 8d ~/.ssh/known_hosts

16. Copy your SSH public key to the server from a host without Ssh-copy-id command

Cat ~/.ssh/id_rsa.pub | SSH [email protected] "mkdir ~/.ssh; Cat >> ~/.ssh/authorized_keys "

If you use Mac OS X or any other *nix variant with no Ssh-copy-id command, this command can copy your public key to a remote host, so you can still implement a password-less SSH login.

17. Real-time SSH network throughput test

Yes | PV | SSH $host "Cat >/dev/null"

Connect to the host via SSH, show real-time transfer speed, point all the transmitted data to/dev/null, need to install PV first.

If it is Debian:

Apt-get Install PV

If it is fedora:

Yum Install PV

(Additional repositories may need to be enabled).

18. If you set up a remote GNU screen that can be reconnected

ssh-t [email protected]/usr/bin/screen–xrr

People always like to open a lot of shells in a text terminal, if the session suddenly interrupted, or you press "Ctrl-a D", the remote host shell will not be affected, you can reconnect, other useful screen commands have "Ctrl-a C" (Open new Shell) and "ctrl-a a" (switch back and forth between shells), visit http://aperiodic.net/screen/quick_reference for a quick reference to the screen command.

19. Continuation of SCP large file

RSYNC–PARTIAL–PROGRESS–RSH=SSH $file _source $US [email protected] $host: $destination _file

It can restore the failed rsync command, which is useful when you transfer large files over a VPN, such as a backed up database, and you need to install rsync on both sides of the host.

Rsync–partial–progress–rsh=ssh $file _source [email protected] $host: $destination _file Local, remote

Or

rsync–partial–progress–rsh=ssh [email protected] $host: $remote _file $destination _file remote, Local

20. Analyze traffic via SSH W/wireshark

SSH [email protected] ' tshark-f "Port!22″-w-' | Wireshark-k-i–

Use Tshark to capture network traffic on a remote host, send raw pcap data over an SSH connection, and display it in Wireshark, press CTRL + C to stop snapping, but also close the Wireshark window and pass a "-C #" parameter to Tshark, Let it only capture the packet type specified by "#", or redirect the data through a named pipe instead of directly to Wireshark via SSH, I recommend you filter the packets to conserve bandwidth, Tshark can use tcpdump overrides:

SSH [email protected] tcpdump-w– ' Port!22′| Wireshark-k-i–

21. Keep SSH session open permanently

Autossh-m50000-t server.example.com ' Screen-raad mysession '

After you open an SSH session, keep it open forever, and for users who use laptops, if you need to switch between Wi-Fi hotspots, you can guarantee that the connection will not be lost after switching.

22, more stable, faster, stronger SSH client

Ssh-4-c-c BLOWFISH-CBC

Force the use of IPV4, compress the data stream, and use Blowfish encryption.

23. Using Cstream to control bandwidth

Tar-cj/backup | Cstream-t 777k | SSH host ' tar-xj-c/backup '

Use bZIP to compress the folder and then transfer to the remote host at a 777k bit/s rate. Cstream also has more features, please visit http://www.cons.org/cracauer/cstream.html#usage for more information, such as:

echo w00t, I ' M 733+ | Cstream-b1-t2

24, one step to transfer SSH public key to another machine

Ssh-keygen; Ssh-copy-id [email protected]; SSH [email protected]

This combination of commands allows you to login without password ssh, note that if there is already an SSH key pair in the ~/.ssh directory of the Local machine, the new key generated by the Ssh-keygen command may overwrite them, Ssh-copy-id copy the key to the remote host and append the ~/to the remote account. Ssh/authorized_keys file, when using SSH connection, if you do not use the key password, call SSH [email protected] Shortly after the remote shell is displayed.

25. Copy the standard input (stdin) to your X11 buffer

SSH [email protected] cat/path/to/some/file | Xclip

Do you use SCP to copy files to your work computer so that you can copy their contents into an e-mail message? Xclip can help you, it can copy the standard input to the X11 buffer, all you need to do is click the middle mouse button to paste the contents of the buffer.

26. Copy the files of the target machine to local (no SCP case)

SSH [email protected] "Cat/path/to/some/file" Cat >>/path/to/some/file


SSH Command parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.