Ubuntu 18.04 Setup SSH Public Key Authentication

Ubuntu 18.04 Setup SSH Public Key Authentication

Setting up SSH public key authentication on Ubuntu 18.04 is a simple and secure way to access your server over SSH. Here is a step-by-step guide to help you set up SSH public key authentication on your Ubuntu 18.04 server:

  1. On the client machine (the machine you will use to connect to the server), generate an SSH key pair if you do not already have one. To generate an SSH key pair, open a terminal and enter the following command:
ssh-keygen -t rsa
S‮‬ource:www.lautturi.com

This will prompt you to enter a passphrase for your SSH key. It is recommended to use a passphrase to increase the security of your key. However, if you prefer not to use a passphrase, you can simply press Enter to leave it blank.

  1. Copy the public key to the server. To do this, you can use the ssh-copy-id command. First, log in to the server using the ssh command and your username and password. Then, run the following command on the client machine:
ssh-copy-id username@server_ip

Replace username with your username on the server and server_ip with the IP address of the server. This will copy your public key to the authorized_keys file on the server.

  1. On the server, edit the /etc/ssh/sshd_config file to enable public key authentication. To do this, open the file with a text editor and make sure that the following line is uncommented (i.e. does not have a # character at the beginning):
PubkeyAuthentication yes
  1. Restart the sshd service to apply the changes:
systemctl restart ssh
  1. You can now log in to the server using your SSH key. On the client machine, run the following command:
ssh username@server_ip

Replace username with your username on the server and server_ip with the IP address of the server. If you set a passphrase for your SSH key, you will be prompted to enter it.

That's it! You have now set up SSH public key authentication on your Ubuntu 18.04 server.

Created Time:2017-10-30 14:27:24  Author:lautturi