Source

Wiki Pages / SSH

**SSH** or **Secure Shell** is a network protocol that allows data to be exchanged using a secure channel between two networked devices.

== Tips

=== Generate an SSH Key

{{{#!console
$ ssh-keygen
}}}

=== Copy SSH Keys to a remote host.

{{{#!console
$ ssh-copy-id user@workstation
}}}

If your computer doesn't have ssh-copy-id:

{{{#!console
$ cat ~/.ssh/id_rsa.pub | ssh user@workstation "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
}}}

I personally use [[https://github.com/myles/dotfiles/blob/master/shell/functions#L2|this bash function]]:

{{{#!bash
add_auth_key () {
	host=$1
	if [ -z $host ]; then
		echo "You must provide a host as the first (and only) argument"
		return
	fi
	if [ ! -f ~/.ssh/id_rsa.pub ]; then
		command ssh-keygen -t rsa
	fi
	command scp ~/.ssh/id_rsa.pub $host:/tmp/tmp_rsa
	command ssh $host -t "if [ ~ -d ~/.ssh ]; then mkdir ~/.ssh/;fi && cat /tmp/tmp_rsa >> ~/.ssh/authorized_keys && rm /tmp/tmp_rsa && chmod -R 700 ~/.ssh"
}
}}}

=== SSH Connection through host in the middle

{{{#!console
$ ssh -t user@dmz ssh user@workstation
}}}

This will open an SSH session with the dmz server then on that computer open another session on the workstation.

=== Attach to a remote screen session over SSH

{{{#!console
$ ssh -t user@workstation screen -r
}}}

== Resources

* [[http://www.revsys.com/writings/quicktips/ssh-tunnel.html|SSH Tunneling Made Easy]]
* [[http://blog.urfix.com/25-ssh-commands-tricks/|25 Best SSH Commands/Tricks]]