How to Enable & Disable SSH login on Linux Cloud Servers

SSH (Secure shell) is a cryptographic network protocol used to connect to a remote server securely and it transfers the data in encrypted form between the host and the client. The default TCP/IP port for the SSH is 22.

 

This guide will describe the steps to enable and disable SSH login in the Linux server.

 

CentOS

By default, the OpenSSH Server Software Package is included on CentOS. If it is not present, please complete the following procedure.

 

  1. Run the below command to install OpenSSH Server Software Package.

    # yum install openssh-server openssh-clients
    

    linuxssh1

  2. Run the below command to start and check the status of the SSH daemon on the OpenSSH server.

    # systemctl start sshd  
    # systemctl status sshd
    

    linuxssh2

 

Enable SSH login (CentOS)

 

  1. Run the below command and then reboot the server to Enable SSH.

    # systemctl enable sshd
    

    linuxssh3

  2. Once it is enabled, the server can access it via PUTTY as shown below.

    linuxssh4

    NOTE: Replace the sample IP (123.123.123.123) with the original server IP and replace the port if set custom.

    linuxssh5

  3. Enter the password to access the server.

 

Disable SSH login (CentOS)

 

  1. Run the below command and then reboot the server to Disable SSH.

    # systemctl disable sshd
    

    linuxssh6

  2. Once the SSH is disabled, then will get the below warning message while trying to SSH to the server.

    linuxssh7

 

Ubuntu / Debian

By default, the OpenSSH Server Software Package is included on Ubuntu & Debian. If it is not present, please complete the following procedure.

 

  1. Run the below command to install OpenSSH Server Software Package.

    # apt-get install openssh-server -y
    

    linuxssh8

  2. Run the below command to start and check the status of the SSH daemon on the OpenSSH server.

    # systemctl start sshd
    # systemctl status sshd
    

    linuxssh9

 

Enable SSH login (Ubuntu / Debian)

 

  1. Run the below command and then reboot the server to Enable SSH.

    # systemctl enable ssh
    

    linuxssh10

  2. Once it is enabled, the server can access it via PUTTY as shown below.

    linuxssh11

    NOTE: Replace the sample IP with the original server IP (123.123.123.123) and replace the port if set custom.

    linuxssh12

  3. Enter the password to access the server.

 

Disable SSH login (Ubuntu / Debian)

 

  1. Run the below command and then reboot the server to Disable SSH.

    # systemctl disable ssh
    

    linuxssh9

  2. Once the SSH is disabled, then will get the below warning message while trying to SSH to the server.

    linuxssh9

Was this answer helpful? 0 Users Found This Useful

Related Articles

Complete List of Common Linux Server Commands

Mastering common Linux commands is the foundation of server management. File and Directory...

Detailed Tutorial on Linux Server Firewall Configuration

Firewall is the first line of defense for server security, and proper configuration is essential....

Steps and methods for handling zombie processes on Linux cloud servers

In daily use of Linux cloud servers, many website owners will encounter processes with a state of...

What to do if the cloud server port is occupied due to Nginx configuration error?

In the process of deploying or modifying Nginx configuration, many users often overlook a key...

Setting up Two-Factor Authentication for Linux Server

Why Use 2FA on a Linux Server? Despite their strong security, SSH keys are not infallible,...