Step 1: Edit the SSH Configuration File
Open the SSH configuration file using a text editor. You can use
nano,vi, or any other text editor you prefer. Here, we'll usenano:bash1sudo nano /etc/ssh/sshd_configLook for the line that says:
plaintext1PermitRootLogin noIf it exists, change it to:
plaintext1PermitRootLogin yesIf the line does not exist, you can add it.
Save the changes and exit the editor. In
nano, you can do this by pressingCTRL + X, thenYto confirm, andEnterto save.
Step 2: Restart the SSH Service
After making changes to the SSH configuration, you need to restart the SSH service for the changes to take effect:
bash1sudo systemctl restart sshd
Step 3: Configure Firewall (if applicable)
If you have a firewall enabled, ensure that SSH traffic is allowed. You can do this with the following commands:
bash1sudo firewall-cmd --permanent --add-service=ssh 2sudo firewall-cmd --reload
Step 4: Set a Strong Password for the Root User
If you haven't already set a strong password for the root user, you can do so with the following command:
bash1sudo passwd root
Step 5: Verify SSH Access for Root
You can now attempt to SSH into your CentOS 9 server as the root user. Use the following command, replacing server_ip with the actual IP address of your server:
bash1ssh root@server_ip