How to Install and Configure an SSH Server on Debian ⋆ ALexHost SRL

Test your skills on our all Hosting services and get 15% off!

Use code at checkout:

Skills
30.10.2024

How to Install and Configure an SSH Server on Debian

SSH (Secure Shell) is a protocol that provides a secure way to access and manage remote servers. Installing and configuring an SSH server on Debian allows you to remotely control your server securely over a network.

In this article, we’ll cover how to install and configure an SSH server on Debian.

Step 1: Install OpenSSH Server

The OpenSSH server is the most commonly used SSH implementation. To install it on Debian, open a terminal and run the following command:

sudo apt update sudo apt install openssh-server

Once the installation is complete, verify that the SSH service is running:

sudo systemctl status ssh

Step 2: Configure SSH

The SSH configuration file is located at /etc/ssh/sshd_config. Open this file with a text editor:

sudo nano /etc/ssh/sshd_config

You can modify various settings to enhance security and functionality:

  • Change the SSH Port (Optional): To change the default SSH port (which is 22), modify the following line:
    Port 2222
  • Disable Root Login (Recommended): To improve security, disable root login by changing:
    PermitRootLogin no
  • Allow Only Specific Users (Optional): You can restrict SSH access to specific users by adding:
    AllowUsers username

After making changes, save and close the file.

Step 3: Restart the SSH Service

To apply the changes, restart the SSH service:

sudo systemctl restart ssh

Step 4: Access the Server via SSH

You can now access your server via SSH from another machine. Use the following command:

ssh username@your_server_ip

If you changed the port, specify the port number like this:

ssh -p 2222 username@your_server_ip

Step 5: Enable SSH Key Authentication (Optional)

For added security, you can set up SSH key authentication. This method eliminates the need for passwords and provides a more secure way to authenticate.

  1. Generate SSH Keys on the client machine:
    ssh-keygen -t rsa -b 4096
  2. Copy the Public Key to the server:
    ssh-copy-id username@your_server_ip

Now, when you log in, you will be prompted for your SSH key passphrase instead of a password.

Conclusion

Installing and configuring an SSH server on Debian is a straightforward process that provides secure remote access to your server. By following this guide, you’ll have SSH up and running with additional options for improving security, such as changing the default port, disabling root login, and enabling SSH key authentication.

Test your skills on our all Hosting services and get 15% off!

Use code at checkout:

Skills