Introduction
SSH (Secure Shell) keys provide a more secure way of logging into a server with SSH than using a password alone. In this guide, we'll walk through the steps to generate SSH keys on Ubuntu 20.04 and configure them for use.
Prerequisites
Before proceeding, ensure you have:
- An Ubuntu 20.04 server
- A local computer with SSH client installed
Steps to Set Up SSH Keys
- Generate SSH Key Pair: Open a terminal on your local computer and run the following command to generate an SSH key pair:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- Copy Public Key to Server: Use the following command to copy the public key to your Ubuntu 20.04 server:
ssh-copy-id username@hostname
- Configure SSH: Edit the SSH configuration file on your Ubuntu 20.04 server to disable password authentication and enable public key authentication:
sudo nano /etc/ssh/sshd_config
Add or modify the following lines:
PubkeyAuthentication yes
PasswordAuthentication no
- Reload SSH Service: Reload the SSH service to apply the changes:
sudo systemctl reload sshd
Conclusion
Congratulations! You have successfully set up SSH keys on your Ubuntu 20.04 server and configured them for use. SSH keys provide a more secure way to authenticate with your server compared to password-based authentication.