One of the nice things about ssh is that you can set things up so that it becomes really easy to use. In this short tip I will show you here how to do the following:
  1. Setup key-pairs so that you don't need a password to login to another machine using ssh, sftp or scp.
  2. Configure ssh "aliases" to increase our ssh efficiency
  3. Setup Expandrive to use these shorthands.

1. Generating Key-Pairs

Here I will assume that if you are using ssh then you already know your way around a terminal session. The first thing we need to do is open the terminal and go to the .ssh directory. Create it if it does not already exist and make sure it is readable only by you.

mkdir .ssh
chmod 700 .ssh
cd .ssh


Now suppose that the machine you want to login to is called pogo, issue the following commands to create a key-pair for that machine and register it with the ssh-agent and when prompted for a password just press "enter" twice:

ssh-keygen -f pogo
ssh-add pogo


Note that you don't need to name your key-pair with the same name as your target machine. In fact you could re-use the same key-pair to connect to any number of machines. Now that we have our keys setup we need to our public-key pogo.pub to the end of the ~/.ssh/authorized_keys on the target machine. This can be done in many ways but here is an easy one:

cat pogo.pub | ssh user@pogo.network.com \
'cat - >> ~/.ssh/authorized_keys'
ssh-add pogo


Here I assume that the .ssh directory on the remote machine already exists. If not you will need to create it first. When prompted, enter your password. Now you should be able to login withou entering a password. Try loging in using ssh:

ssh user@pogo.network.com


2. Configure SSH Aliases

Now edit a file named config (you should still be in the .ssh directory), add the following lines to it and then save the file:

Host blog
    Hostname      pogo.network.com
    User          user
    IdentityFile  ~/.ssh/pogo


These lines now allow you shorten the login command to

ssh blog


Better yet it also works with other ssh related commands such as sftp and scp. If you want to use sftp (you will indirectly if you use ExpanDrive) you will need to remove any .bashrc file on the remote server (use .bash_profile instead) otherwise you might get a "Received message too long 1500476704" error.

3. Setup Expandrive

This is really easy. Just fire-up the ExpanDrive drive manager and create a new entry. Put the shorthand or alias in the server field (this would be "blog" in our case) and connect. See your ssh aliases even work with expandrive! Now all your Mac apps can access the remote filesystem and you don't need to remember any passwords.

Have Fun!

Comments