CentOS SSH Installation And Configuration

To install and configure SSH on CentOS, follow these steps:

  1. Install SSH server: Open a terminal and run the following command to install the SSH server:
    sudo yum install openssh-server
  2. Start the SSH service: After the installation is complete, start the SSH service by running the following command:
    sudo systemctl start sshd
  3. Enable SSH service to start at boot time: To ensure that the SSH service starts automatically at boot time, run the following command:
    sudo systemctl enable sshd
  4. Configure SSH: By default, SSH allows all users to connect to the server. You can modify the configuration file to allow only certain users or groups to connect. To do this, open the SSH configuration file in a text editor:
    sudo vi /etc/ssh/sshd_config

    Here are some common configuration options:

    • To allow only certain users or groups to connect, add the following line to the configuration file:
      AllowUsers user1 user2

      Replace user1 and user2 with the usernames of the users who are allowed to connect.

    • To change the port that SSH listens on, modify the following line:
      #Port 22

      Remove the “#” symbol and change “22” to the desired port number.

    • To disable password authentication and only allow key-based authentication, add the following line:
      PasswordAuthentication no

    Save the changes to the configuration file and exit the text editor.

  5. Restart SSH: After making changes to the SSH configuration file, you need to restart the SSH service for the changes to take effect. Run the following command:
    sudo systemctl restart sshd

SSH should now be installed and configured on your CentOS server. You can test the SSH connection by connecting to the server from another computer using an SSH client, such as PuTTY. (https://locals.md/)

Leave a Comment