How to Enable SSH on Linux
Enabling SSH on Linux provides secure remote access to your system, allowing you to manage servers, transfer files, and execute commands from anywhere. This guide walks you through the entire process, from installing the OpenSSH server package to testing the connection, while highlighting key security considerations.
Prerequisites
Before you begin, make sure your Linux distribution meets the following requirements:
- Root or sudo privileges – you need administrative rights to install packages and modify system services.
- Internet connectivity – to download the OpenSSH server package from the official repositories.
- A basic understanding of the command line – most configuration steps are performed via terminal commands.
Installing OpenSSH Server
Using APT (Debian/Ubuntu)
sudo apt update
sudo apt install openssh-server
Using YUM/DNF (CentOS/RHEL/Fedora)
sudo yum install openssh-server # for older CentOS versions
# or
sudo dnf install openssh-server # for newer Fedora/CentOS 8+
Using Pacman (Arch Linux)
sudo pacman -Syu openssh
After installation, the SSH daemon (sshd) is installed but not yet running.
Enabling and Starting the SSH Service
Systemd‑based systems (most modern distributions)
sudo systemctl enable sshd # enable at boot
sudo systemctl start sshd # start immediately
SysVinit systems (older distributions)
sudo service sshd start
sudo chkconfig sshd on # enable at boot
Verify that the service is active:
sudo systemctl status sshd
You should see a line indicating that sshd is active (running) Easy to understand, harder to ignore..
Configuring SSH (Optional but Recommended)
The main configuration file is /etc/ssh/sshd_config. While the default settings work for most users, you may want to adjust a few key parameters to improve security and usability Worth keeping that in mind..
Edit the Configuration File
sudo nano /etc/ssh/sshd_config
Important settings to review:
- Port – By default, SSH listens on port 22. Changing this to a non‑standard port (e.g., 2222) can reduce automated attacks.
Port 2222 - PermitRootLogin – Disabling direct root login forces users to log in as a regular user and then use
sudo.PermitRootLogin no - PasswordAuthentication – If you plan to use key‑based authentication only, disable password logins.
PasswordAuthentication no - AllowUsers – Restrict SSH access to specific usernames.
AllowUsers alice bob
After editing, restart the daemon to apply changes:
sudo systemctl restart sshd
Testing the SSH Connection
From the same machine (localhost), you can test the service with:
ssh localhost -p 2222
If you are connecting from a different computer, use its IP address or hostname:
ssh alice@192.168.1.10 -p 2222
You will be prompted for the user’s password (or for a private key if password authentication is disabled). A successful login confirms that SSH is enabled and operational Less friction, more output..
Securing Your SSH Server
1. Use Key‑Based Authentication
Generate a key pair on your client machine:
ssh-keygen -t ed25519 -C "your_email@example.com"
Copy the public key to the server:
ssh-copy-id -i ~/.ssh/id_ed25519.pub alice@192.168.1.10
Then ensure PasswordAuthentication no in sshd_config Surprisingly effective..
2. Enable Two‑Factor Authentication (2FA)
Install the google-authenticator package and follow the setup guide to add a time‑based one‑time password (TOTP) layer Easy to understand, harder to ignore. Still holds up..
3. Limit Login Attempts
Edit the file /etc/pam.d/sshd and add the pam_faildelay and pam_tally2 modules, or use the MaxAuthTries directive in sshd_config.
4. Use a Firewall
Allow SSH traffic only on the configured port via iptables or ufw:
sudo ufw allow 2222/tcp
Common Issues and Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
Connection refused |
SSH daemon not running | sudo systemctl start sshd |
Permission denied (publickey) |
Wrong key permissions or missing key | Ensure ~/.ssh is 700 and ~/.ssh/authorized_keys is 600 |
sshd: no hostkeys available |
Missing SSH host keys | Run sudo ssh-keygen -A to generate them |
iptables: Permission denied |
Firewall rules not applied | Verify you have root privileges and correct syntax |
ssh: connect to host port 22: Connection timed out |
Port blocked by network firewall | Open the port in your router or cloud provider security group |
Conclusion
Enabling SSH on Linux is a straightforward process that empowers you with secure, remote administration capabilities. By following the steps outlined above—installing the OpenSSH server, enabling the service, configuring sshd_config, and applying essential security measures—you can confidently manage your Linux machines from anywhere. Remember to keep your SSH configuration up to date, favor key‑based authentication, and regularly review firewall rules to maintain a strong and resilient remote‑access environment And that's really what it comes down to..
With SSH now enabled, you have the foundation needed for automation, remote troubleshooting, and secure file transfers, making your Linux experience both powerful and safe.