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_configFind
#Port 22and change it to a custom port:Port 2222Disable Root Login: In the same file, find
#PermitRootLoginand update it:PermitRootLogin noEnable Key-Based Authentication:
- Generate SSH keys on the client:
ssh-keygen -t rsa -b 4096 - Copy the public key to the server:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@server_ip
- Generate SSH keys on the client:
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.