Introduction
SSH (Secure Shell) is a network protocol that allows you to log in to another computer over a network and execute commands on a remote system or transfer files. In this article, we will go through the step-by-step process of installing an SSH server on an Ubuntu system, configuring it to start automatically, and connecting to the SSH server.
Installing the SSH Server
First, open a terminal and update the list of packages:
1sudo apt updateInstall the OpenSSH server:
1sudo apt install openssh-serverOnce the installation is complete, the SSH service should be started automatically. To check the status of the SSH service, enter the following command:
1sudo systemctl status sshIf the service is not running, you can start it with this command:
1sudo systemctl start sshEnable the SSH service to start automatically on boot:
1sudo systemctl enable sshThis will make sure that the SSH service is started automatically whenever the system boots up.
Configuring the SSH Server
Open the SSH configuration file:
1sudo nano /etc/ssh/sshd_configYou can change the following settings based on your requirements:
Change Port: You can change the default port 22 to a different port for increased security. For example, to change the port to 2222:
1Port 2222Disable Root Login: You can disable SSH login as the root user for enhanced security:
1PermitRootLogin noDisable Password Authentication: If you are using public key authentication, you can disable password authentication:
1PasswordAuthentication no
Save the changes and exit the editor (Ctrl+O to save, Ctrl+X to exit).
Restart the SSH service to apply the changes:
1sudo systemctl restart ssh
Configuring Firewall
If you are using UFW, which is the default firewall on Ubuntu, you need to allow SSH connections. Check if UFW is active and allow SSH connections:
| |
If you are using a non-standard port, you can allow it by specifying the port like this:
| |
Connecting to the SSH Server
From your client computer, try connecting to the SSH server using this command:
1ssh username@server_ipReplace
usernamewith the username on the server andserver_ipwith the IP address of the server. If you are using a non-standard port, you can specify the port while connecting:1ssh -p 2222 username@server_ipThe first time you connect, you will get a message asking you to trust the server’s authenticity. Type “yes” to continue.
Enter the password and log in.
Security Hardening Tips
Use strong passwords: Use a strong and unpredictable password.
Use public key authentication: Enhance security by utilizing public key authentication instead of passwords.
Use a non-standard port: Use a different port instead of the default port 22 to reduce brute force attacks.
Install fail2ban: To prevent brute force attacks, install
fail2ban:1sudo apt install fail2banRegular updates and patching: Keep your system and packages updated to maintain security.
Conclusion
You now know how to install an SSH server on an Ubuntu system, configure it to start automatically, and connect to the SSH server. SSH is a vital tool for remote system administration, but it is crucial to pay attention to security. By following the security hardening tips mentioned above, you can have a more secure SSH environment.