Adding a Key to Your Server for SSH Login

Using Ubuntu

An authentication key allows your server to authenticate the computer you are using has the right key and should be granted access. This lets you use the key instead of a username and password when using ssh.

If you don’t already have a key on your local machine (look for a file named id_rsa.pub in your user home directory under the .ssh folder

cd /.ssh

will get you to the right directory) then you need to generate the key pair. On your desktop machine use:

ssh-keygen

Next you copy the file to your server. scp ~/.ssh/id_dsa.pub [user]@[server]:.ssh/

scp ~/.ssh/id_dsa.pub username@servername:.ssh/

Rename the file on the server to authorized_keys2

mv id_rsa.pub authorized_keys2

The key is for to authenticate your computer. But on the ssh login Ubuntu will look in the user folder. So if you also had user2 access to the server and tried to ssh into the server you would not be authenticated because it would look in user2/.ssh for the authorized key file and not find it. You can put the same key in any user folder on your server to have that user also be automatically authenticated.

2 thoughts on “Adding a Key to Your Server for SSH Login

  1. Pingback: Upgrading VPS Web Server from Ubuntu 10.04 to 12.04 | Coding and Server Syntax Examples

  2. Pingback: Don’t Copy-Paste Directly from Website to Terminal | Coding and Server Syntax Examples

Leave a Reply

Your email address will not be published. Required fields are marked *

This Blog will give regular Commentators DoFollow Status. Implemented from IT Blögg