How to Set Up SSH Server on Ubuntu
Learn how to install, configure and secure SSH server on Ubuntu with this step-by-step guide covering installation, key-based authentication, and essential security configurations.
Installing SSH Server
To enable remote access to your Ubuntu machine, you'll first need to install the OpenSSH server package. Here's how to do it:
sudo apt update
sudo apt install openssh-server
Verifying Installation
After installation, verify that SSH service is running with these commands:
sudo systemctl status ssh
sudo systemctl enable ssh
sudo systemctl start ssh
Basic SSH Connection
From your client machine, you can now connect using:
ssh username@server_ip
Setting Up Key-based Authentication
For enhanced security, set up SSH keys instead of password authentication:
1. Generate SSH Key Pair
ssh-keygen -t ed25519
2. Copy Public Key to Server
ssh-copy-id username@server_ip
Enhancing Security
After setting up key-based authentication, disable password authentication by editing the SSH configuration:
sudo nano /etc/ssh/sshd_config
Modify these settings:
PasswordAuthentication no
ChallengeResponseAuthentication no
Finally, restart the SSH service:
sudo systemctl restart ssh
Testing
Test your new SSH setup by trying to connect from your client machine. You should now be able to log in using your SSH key without a password prompt.