How to Enable SSH on Ubuntu (Step-by-Step Guide)
Enabling SSH on Ubuntu is essential if you want to manage your machine remotely or automate deployments. In this guide, we’ll walk through how to set it up securely.
1. Install the OpenSSH Server
Run the following commands to update package lists and install the OpenSSH server:
sudo apt update
sudo apt install openssh-server -y
This installs the SSH service and its dependencies.
2. Enable and Start the SSH Service
After installation, enable and start the SSH service so it runs on boot:
sudo systemctl enable ssh
sudo systemctl start ssh
You can verify the service is running:
sudo systemctl status ssh
Look for active (running) in the output.
3. Allow SSH Through the Firewall (Optional)
If you’re using UFW (Uncomplicated Firewall), you’ll need to allow SSH traffic:
sudo ufw allow ssh
sudo ufw reload
This opens port 22 for incoming SSH connections.
4. Test Your SSH Connection
From another machine, connect to your Ubuntu system using:
ssh your-username@your-ubuntu-ip
Replace your-username
with your Ubuntu username and your-ubuntu-ip
with the machine’s IP address.
5. (Recommended) Harden Your SSH Setup
For better security, consider:
- Using SSH keys instead of passwords.
-
Disabling root login via SSH by editing
/etc/ssh/sshd_config
. - Changing the default SSH port to reduce automated attacks.
After making changes to sshd_config
, restart SSH:
sudo systemctl restart ssh
Final Thoughts
That’s it! You’ve successfully enabled SSH on Ubuntu. With SSH running, you can now remotely administer your server, deploy code, and use tools like Ansible or Git to manage your machine more efficiently.
Top comments (0)