How to Install and Configure OpenSSH Server on Debian

Securely managing remote access is essential for any server administrator. This guide will walk you through installing and configuring the OpenSSH server (sshd) on Debian.


1. Update Package List

Keep your package index up to date:

sudo apt-get update

2. Install OpenSSH Server

Install the OpenSSH server package:

sudo apt-get install openssh-server

3. Check SSH Service Status

Verify that the SSH service is running:

sudo systemctl status sshd

4. Enable SSH Traffic on Firewall

If using UFW, allow SSH connections:

sudo ufw allow ssh

5. Configure SSH Server

  • Change Default Port: Edit the SSH configuration file:

    sudo nano /etc/ssh/sshd_config
    

    Find #Port 22 and change it to a custom port:

    Port 2222
    
  • Disable Root Login: In the same file, find #PermitRootLogin and update it:

    PermitRootLogin no
    
  • Enable Key-Based Authentication:

    1. Generate SSH keys on the client:
      ssh-keygen -t rsa -b 4096
      
    2. Copy the public key to the server:
      ssh-copy-id -i ~/.ssh/id_rsa.pub user@server_ip
      

6. Restart SSH Service

Apply the changes by restarting the SSH service:

sudo systemctl restart sshd

7. Connect to SSH Server

Use your SSH client to connect to the server with the custom port:

ssh -p 2222 user@server_ip

Conclusion

By following these steps, you can successfully set up and configure a secure OpenSSH server on Debian. For added security, consider further customizations, such as limiting user access or implementing fail2ban.

Related Posts