OpenSSH is an open-source suite of secure networking utilities that provides encrypted communication sessions over a computer network using the SSH protocol. The OpenSSH server is widely used on Linux systems to enable secure remote access and file transfers. In this article, we will provide a step-by-step guide on installing or updating the OpenSSH server on Ubuntu, Linux Mint and other Debian-based systems.

Advertisement

Step 1: Update Your System

Before installing or updating the OpenSSH server, it is crucial to update your system packages to ensure you are working with the latest software. To update your system, run the following commands:

sudo apt update 
sudo apt upgrade 

Step 2: Install the OpenSSH Server

To install the OpenSSH server on your Ubuntu or Debian system, run the following command:

sudo apt install openssh-server 

The system will download and install the OpenSSH server package and its dependencies.

Step 3: Verify the OpenSSH Server Installation

After the installation is complete, verify that the OpenSSH server is running using the following command:

sudo systemctl status ssh 

The output should indicate that the OpenSSH server is active and running:

Output:
ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2023-03-30 10:53:21 UTC; 1min 20s ago

Step 4: Configure the OpenSSH Server

To configure the OpenSSH server, you need to edit the sshd_config file located in the /etc/ssh/ directory. Use your preferred text editor to open the file:

sudo nano /etc/ssh/sshd_config 

Here are some common configuration settings you may want to modify:

  • Port: By default, the OpenSSH server listens on port 22. You can change this to a different port number to enhance security.
  • PermitRootLogin: This setting determines whether the root user can log in via SSH. For security reasons, it is recommended to disable root login by setting this value to no.
  • PasswordAuthentication: If you want to use public key authentication instead of passwords, set this value to no.
  • AllowUsers: To restrict SSH access to specific users, add this line followed by the usernames separated by spaces, e.g., AllowUsers user1 user2.

After making any necessary changes, save and close the file. To apply the new configuration, restart the OpenSSH server using the following command:

sudo systemctl restart ssh 

Step 5: Configure the Firewall (Optional)

If your system is using a firewall, you need to allow incoming SSH connections. The default firewall on Ubuntu and Debian systems is UFW (Uncomplicated Firewall). To allow SSH connections through UFW, run the following command:

sudo ufw allow ssh 

If you changed the default SSH port in Step 4, replace “ssh” with the new port number, e.g., sudo ufw allow 2222/tcp.

Step 6: Test the SSH Connection

To test your SSH connection, open a new terminal window on your local machine or another system within the same network and use the following command:

ssh username@your_server_ip_address 

Replace username with your Ubuntu or Debian system’s username and your_server_ip_address with the IP address of the system where the OpenSSH server is installed.

If you changed the default SSH port in Step 4, add the -p flag followed by the new port number, e.g., ssh -p 2222 username@your_server_ip_address.

You should be prompted to enter your password or the passphrase for your private key if you have set up public key authentication. After successful authentication, you will be connected to the remote system via SSH.

Step 7: Update the OpenSSH Server (Optional)

To update the OpenSSH server to the latest version, you can use the standard package update procedure. Run the following commands to update your system packages and the OpenSSH server:

sudo apt update 
sudo apt upgrade 

After updating the OpenSSH server, restart it to apply the changes:

sudo systemctl restart ssh 

Conclusion

This article provided a comprehensive guide on installing or updating the OpenSSH server on Ubuntu and Debian-based systems. By following these steps, you have successfully installed, configured, and tested the OpenSSH server. With the OpenSSH server in place, you can securely access and manage your Linux systems remotely, ensuring safe and encrypted communication across your network.

Share.

1 Comment

  1. Hi: Rahul!
    I’m running Mininet-VM on Oracle VirtualBox.
    When I write “sudo systemctl status ssh” in the Mininet terminal window, it gives me the following error:

    *sudo: systemctl: command not found*

    so, please help me in this regard!
    THANKS

Leave A Reply


Exit mobile version