DEV Community

Divyanshu Tiwari
Divyanshu Tiwari

Posted on

Setup and Configure SSH on Ubuntu 22.04

Steps to set up SSH on Ubuntu 22:
๐Ÿ› ๏ธ Step 1: Prepare Your System
Before installing SSH, ensure your system is up-to-date:
sudo apt update && sudo apt upgrade

๐Ÿ” Step 2: Install OpenSSH Server
To install the OpenSSH server package:
sudo apt install openssh-server

๐Ÿš€ Step 3: Start and Enable SSH Service
Enable and start the SSH service:
sudo systemctl enable --now ssh
Verify that the SSH service is running:
sudo systemctl status ssh

๐Ÿ”ฅ Step 4: Configure the Firewall
If you're using UFW (Uncomplicated Firewall), allow SSH connections:
sudo ufw allow ssh
Check the status of UFW to ensure SSH is allowed:
sudo ufw status

๐ŸŒ Step 5: Connect to the Server
To connect to your server via SSH, use the following command:
ssh username@server_ip
Replace username with your actual username and server_ip with your server's IP address.

โš™๏ธ Optional: Configure SSH for Enhanced Security
To enhance security, consider editing the SSH configuration file:
sudo nano /etc/ssh/sshd_config


Some recommended changes:
โ€ข Disable root login:
โ€ข PermitRootLogin no
โ€ข Change the default port (e.g., to 2222):
Port 2222
After making changes, restart the SSH service:
sudo systemctl restart ssh

Top comments (0)