How to create and use SSH-keypairs

Done on Ubuntu 16.04 LTS 64-bit


How to create and use SSH-keypairs

First create a hidden directory to your users home directory,

sudo mkdir /home/kristian/.ssh

Add your authorized keys file inside the .ssh directory,

touch /home/kristian/.ssh/authorized_keys

Change permissions for the directory and the authorized keys file.

sudo chmod 700 /home/kristian/.ssh
sudo chmod 600 /home/kristian/.ssh/authorized_key

Next create yourself a keypair that you will use while connecting with SSH.

ssh-keygen -t rsa -b 4096 -C "Kristians Key"

Name it, add secret passphrase if you want and save it. Then copy the contents of the public key and add it to your authorized_keys file.

Save your private key somewhere safe as you will use it to connect using SSH.

Restart your ssh-daemon and connect using your private key.

ssh -i privatekey.txt kristian@IP-Address

Insert secret passphrase (if added) and your in.

 

ICT-Infrastructure student from Finland.

Learning Linux, DevOps and Docker…

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.