1. copy ssh key to remote host

ssh-copy-id [email protected]_host

2 map the tunnel the remote host 80 port to local host port 2001

ssh -N -L2001:localhost:80 remote_host

# now we can use localhost:2001 to reach remote_host 80

  1. compare the local file and remote file

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

  1. jump point to unreachable_host

ssh -t reachable_host ssh unreachable_host

  1. copy file from remote_host1 to remote_host2

# please keep in mind, you can reach both remote host

ssh [email protected]_host1 "cd /somedir/tocopy/ && tar -cf – ." | ssh [email protected]_host2 "cd /samedir/tocopyto/ && tar -xf -"

  1. use screen to keep session alive even disconnected.

# make sure remote_host has screen

ssh -t remote_host screen –r

  1. copy db to new db server with 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"

  1. remove the “key change warning”

#actually, this is sed tips 🙂

sed -i 8d ~/.ssh/known_hosts

  1. copy the public key to remote host

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

  1. copy huge files to remote host, keep rsync available from both side

# local -> remote

rsync -–partial -avP -–rsh=ssh $file_source [email protected]$host:$destination_file

# remote -> local

rsync –-partial -avP -–rsh=ssh [email protected]$host:$remote_file $destination_file