Ubuntu SSH SSHFS Tunnel

From richud.com
Jump to: navigation, search


SSH

Simple example to get ssh authorisation working without needing a password

Get openSSH package and generate your key pair

$ sudo apt-get install ssh
#Generate your keys
$ ssh-keygen -t rsa

This should create your secret id_rsa private key and id_rsa.pub public key in folder ~/.ssh/ (private key only has user read/write)

Open id_rsa.pub in an editor and alter the yourusername@yourlocalhostname at the end of the text to yourusername@*, save it out as authorized_keys

Hence you end up with these in ~/.ssh/

-rw-------  1 1000 1000 1675 2012-04-15 12:07 id_rsa
-rw-r--r--  1 1000 1000  388 2012-04-15 12:07 id_rsa.pub
-rw-r--r--  1 1000 1000  386 2012-04-15 12:08 authorized_keys

For any SSH server you need to connect to, you need to copy this authorized_keys file to your ~/.ssh/ folder on it (usernames must match). (You keep the private key only on your machine.)

If you have say three pc's that connect to your server, you need to have all three of the authorized_keys from them merged into one larger authorized_keys file on the server. You simply use cat to append 'cat authorized_keys >> authorized_keys'

(conversely you could put the same private key on your three pc's so they share the same single entried autorized_keys file on the server)

  • In a nutshell, your authorized_keys file(contents) needs to be copied(merged) into ~/.ssh/authorized_keys on the server you are connecting to.

You can automate this - the below copies the .pub key to the authorized_keys on the targetserver (but bear in mind you'd either need to edit the user@* directly in your pub file first, or edit the authorized_keys on the server afterwards.

ssh-copy-id user@targetserver

SSHFS

You can map a remote hosts filesystem as a mounted folder (via Fuser)

This maps the root folder at richud.com to a local folder I just made /tmp/r

$ sudo apt-get install sshfs
#map
$ sshfs user@richud.com:/ /tmp/r
#unmount
$ fusermount -u /tmp/r