Connect automatically to a remote machine (without typing in the password each time)
The process goes roughly like this: you need to generate a public key that you’ll save in the remote machine. It’s the way of saying to it: this computer is authorised to connect to you, and this is my way of proving I am who I say I am.
To generate a public key, open a terminal in your local machine (the machine that you’ll connect to the remote server) and type the following:
ssh-keygen -t dsa
When prompted, leave the passphrase empty. You can select which file to store the key in, remember the one you select (default is ~/.ssh/id_dsa).
ssh-keygen will actually generate two files. One contains your private key and the other contains the public key. In this case, id_dsa contains the private key, and id_dsa.pub contains the public key. You MUST NEVER REVEAL your private key to anyone since that means that people with access to it would be able to decrypt encrypted content signed with your key.
So now open the generated id_dsa.pub file and copy its contents to the ~/.ssh/authorized_keys in the remote machine. If there are any existing keys, just append the new contents to the end of the file.
At this point you could connect just using
ssh server.address -l username
but we want to type even less, something in the lines of
To do so you need to add an alias in your local ssh config file. If the file doesn’t exist, create it at ~/.ssh/config and add the following:
That should do!