Coding Knowledge Center
|Setup SSH (1. ssh-keygen - dsa)|
1) ssh-keygen -t dsa 2) ssh-keygen -t rsa
1) Creates dsa encrypted keys. Creates ~/.ssh/id_dsa (private key). Creates ~/.ssh/id_dsa.pub (public key). 2) Creates rsa encrypted keys. Creates ~/.ssh/id_rsa (private key). Creates ~/.ssh/id_rsa.pub (public key).
|Setup SSH (2. dir structure)|
~/.ssh authorized keys: list of public keys which will be granted access and require no login password id_dsa: private dsa encypted key id_dsa.pub: public dsa encrypted key id_rsa: private rsa encrypted key id_rsa.pub: public rsa encyrpted key known_hosts: list of known host keys the current user has previously secure shelled to
Typical secure shell home directory file contents.
|Setup SSH (3. authorized_keys file)|
cat id_dsa.pub >> $HOME/.ssh/authorized_keys
Put your public key in this file on the remote server so it will no longer prompt for password. CAVEAT: make sure the entire key is all on one line! The best way to do this is to copy id_[dsa/rsa].pub to the remote server and then type the above line.
|Setup SSH (4. Organize keys)|
~/.ssh/ site1/ id_dsa id_dsa.pub id_rsa id_rsa.pub site2/ id_dsa id_dsa.pub id_rsa id_rsa.pub > ssh -i ~/.ssh/site1 email@example.com > ssh -i ~/.ssh/site2 firstname.lastname@example.org
TIP! You can actually organize your keys in various sub directories and then specify which set to use when using ssh. Use the -i option to tell ssh where to access the keys that are to be used.
|scp (Copy dirs/files)|
scp [dir/file] [hostname]:[dir/file] scp [dir/file] [user]@[hostname]:[dir/file]
Secure copy [dir/file] to [hostname] as [dir/file]. Secure copy [dir/file] as [user] to [hostname] as [dir/file].
|sftp (Copy dirs/files)|
1) sftp [dir/file] [login]@[hostname]:[dir/file] 2) sftp -b [input file] [login]@[hostname]
1) Secure ftp [dir/file] to [hostname] as [dir/file]. 2) Secure ftp in batch mode using commands in input file.
ssh [login]@[hostname] ssh -l [login] [hostname]
Secure shell as [login] to [hostname].
ssh remotehost "cat remote_file" | diff - "local_file"
Connect to a remote host and perform a diff between a remote and local file.
ssh -L 9001:localhost:21 steved@blackbox > ftp localhost 9001
Port forward an ssh connection to port 9001. Ftp through encrypted port 9001.