SSH Keying through the Terminal on Linux or Mac OS X

SSH keys are fairly simple to setup, especially when using the native terminal applications available in either Linux or Mac OSX. Here's how!

In terminal, type the following command:

ssh-keygen -t dsa

This will ask you a few questions, the defaults for which are just fine, no passcode is necessary. This will generate a key in the ~/.ssh/ directory. Now we just need to get that file up to the server.

You can do this using scp, or rsync. Below is an example of a properly formatted rsync command, be sure to replace username with the username intended to access the server and the IP address with the address of your server:

rsync -av -e "ssh" ~/.ssh/

In the event your server uses a non-standard port for ssh, you can specify this inside the quotes around ssh. Here is an example for port 2222, the default port for HostGator shared servers:

rsync -av -e "ssh -p 2222" ~/.ssh/

Once running this command you will be prompted for your root password, as rsync creates an SSH connection to transfer the file to your server. Once the password is entered the file will be synced up to the server.

Now we want to ensure that all is well on the recipient server. SSH into your server and run the following commands:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown username. ~/.ssh/authorized_keys

That's it! You should be all set! Now to access your server you need only do the following:


The server should automatically accept your key and log you into shell as the specified user.

Please contact us via phone or Live Chat if you have any questions or require assistance.