SSH Key through Terminal - Linux or MacOS 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
This will ask you a few questions, the defaults for which are just fine. Do not enter a password when asked; please simply press return. Once this has been completed it will generate a key in the ~/.ssh/ directory. Now we just need to get that file up to the server.
Below is an example of a properly formatted command that does so. Be sure to replace username with the username intended to access the server and the IP address with the address of your server:ssh-copy-id -i ~/id_rsa.pub email@example.com
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:ssh-copy-id -p 2222 -i ~/id_rsa.pub firstname.lastname@example.org
Once running this command you will be prompted for your root password. After 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:ssh email@example.com
The server should automatically accept your key and log you into shell as the specified user.