DEV Community

John  Ajera
John Ajera

Posted on

How to Enable SSH on Ubuntu

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

You can verify the service is running:

sudo systemctl status ssh
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)