ssh keys: ssh-keygen & ssh-copy-id quick and simple

Ssh keys are a great way to simplify remote access to your linux server. By default you will likely set up a username and password scenario where every time you need to connect to the server through the console or to copy files using scp, sftp you need to enter your password. If you need to access your server frequently and need to copy files regularly then setting up ssh keys will make life much easier. To spell it out, once you set up your ssh keys you will no longer need to enter your password from the machine which you copy your keys from. It may seem unintuitive at first(It was for me). But it is more secure believe it or not.

Quick and Dirty

To keep this as quick and simple as possible we will skip directly to ssh-copy-id.

Step one ssh-copy-id

On your local linux computer console enter: ssh-copy-id yourusername@thenameofyourserver

If you already have keys the server will ask for your password. Enter the password and the keys will copy. The next time you try to connect/login to the server you will not be asked for a password.

If you do not have keys it will tell you that you have no keys. If you have no keys don't worry. In the next step we will generate them.

Step two ssh-keygen

Generate keys with ssh-keygen:

type: ssh-keygen

When asked to enter file in which to save key: Press enter

When asked for password: Press enter for no password. Then enter again for no password.

Now go back to step one and use ssh-copy-id.

congratulations you can now ssh into your server without entering a password from your local computer.

This is meant as a quick and simple reference

As you may have already imagined steps one and two could be reversed unless you already generated keys in the past or your computer comes with keys already generated. When generating keys you can also specify stronger encryption and if you choose to add an optional password you will add addtional security in case your computer is stolen or the physical computer is in a location where a hacker might be able to gain access to your local account. See the following article for more details on how to use ssh keys. SSH Essentials: Working with SSH Servers, Clients, and Keys