Login via SSH using a key file

Configuration for private/test environment only - do not use in production! You need to execute all steps as root.

Generating the key pair on client (rsa 2048-Bit key):
(client = local computer // server = remote computer)

# ssh-keygen -b 2048 -t rsa

This will generate two files: id_rsa and id_rsa.pub in the folder /home/<user>/.ssh.
id_rsa identifies the user and the computer and must not be made public.
id_rsa.pub will be copied to the server and added to the authorized_keys file.

Installing the public key on the server:

Copy the public key

# cd /home/<user>/.ssh
# sftp <server>
sftp> put id_rsa.pub
sftp> quit

Add the public key to authorized_keys file

# ssh <server>

Create .ssh folder (if doesn't exists)

# mkdir .ssh
# chmod 700 .ssh

Insert the public key in authorized_keys:

# cat id_rsa.pub >> .ssh/authorized_keys

If the file is just created:

# chmod 600 .ssh/authorized_keys

Clean up:

# rm id_rsa.pub
Make changes to sshd_config to allow root login and login using a key:

Login as root on server

Change the following in /etc/ssh/sshd_config

PermitRootLogin yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

PermitRootLogin yes should only be done in test enviroments. Use at own risk!

Restart sshd

# service sshd restart