How to Allow and Deny Access for Remote SSH to CentOS 6.2

CentOS 6.2 is an older version of the CentOS operating system, but it is still in use in some environments. By default, CentOS allows remote SSH access to all users who have valid credentials. However, in some cases, you may want to allow or deny remote SSH access for specific users or IP addresses. In this guide, we will show you how to allow and deny access for remote SSH to CentOS 6.2.

Step 1: Edit the SSH Configuration File

The first step is to edit the SSH configuration file on your CentOS 6.2 server. Run the following command:

sudo nano /etc/ssh/sshd_config

This command will open the sshd_config file in the nano text editor.

Step 2: Allow SSH Access for Specific Users

To allow SSH access for specific users, you need to add their usernames to the AllowUsers parameter in the sshd_config file. Find the line that says:

# AllowUsers

Remove the # character at the beginning of the line to uncomment it, then add the usernames separated by spaces. For example:

AllowUsers user1 user2

Save the changes and exit the editor by pressing Ctrl + X, then Y, and finally Enter.

See also  How to Fix "Warning: RPMDB altered outside of yum" Error on Linux Fedora 16 Server

Step 3: Deny SSH Access for Specific Users

To deny SSH access for specific users, you need to add their usernames to the DenyUsers parameter in the sshd_config file. Find the line that says:

# DenyUsers

Remove the # character at the beginning of the line to uncomment it, then add the usernames separated by spaces. For example:

DenyUsers user3 user4

Save the changes and exit the editor by pressing Ctrl + X, then Y, and finally Enter.

Step 4: Allow SSH Access for Specific IP Addresses

To allow SSH access for specific IP addresses, you need to add their IP addresses to the AllowUsers parameter in the sshd_config file. Find the line that says:

# AllowUsers

Remove the # character at the beginning of the line to uncomment it, then add the IP addresses separated by spaces. For example:

AllowUsers 192.168.1.100 192.168.1.200

Save the changes and exit the editor by pressing Ctrl + X, then Y, and finally Enter.

See also  How to Check Disk Read and Write Speed in Linux with HDPARM Utility

Step 5: Deny SSH Access for Specific IP Addresses

To deny SSH access for specific IP addresses, you need to add their IP addresses to the DenyUsers parameter in the sshd_config file. Find the line that says:

# DenyUsers

Remove the # character at the beginning of the line to uncomment it, then add the IP addresses separated by spaces. For example:

DenyUsers 192.168.1.300 192.168.1.400

Save the changes and exit the editor by pressing Ctrl + X, then Y, and finally Enter.

Step 6: Restart the SSH Service

Finally, you need to restart the SSH service to apply the changes. Run the following command:

sudo service sshd restart

Now, remote SSH access will be allowed or denied according to the parameters you set in the sshd_config file.

See also  How to Setup Bind DNS Server in Chroot Jail on CentOS 7

Commands Mentioned:

  • sudo nano /etc/ssh/sshd_config – Edit the SSH configuration file
  • sudo service sshd restart – Restart the SSH service

Conclusion

In this guide, we have shown you how to allow and deny access for remote SSH to CentOS 6.2. By following these steps, you can configure your server to allow or deny SSH access for specific users or IP addresses, improving your server’s security. It is important to remember to test your changes before implementing them in a production environment. If you have any comments or suggestions for improvements, please feel free to share them below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *