Create a persistent connection to the target host in the background, using this command in conjunction with the configuration in your ~/.ssh/config:
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.
Connect directly to a remote screen session (saving the useless parent bash process).
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
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
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
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