Secure Shell (SSH) is a powerful tool for accessing remote systems securely over an encrypted connection. Enabling SSH on a Linux system allows you to remotely manage it, transfer files, and execute commands with enhanced security. In this guide, we'll walk through the steps to enable SSH login on a Linux-based operating system.
Step 1: Login as root user as shown below screenshot
Step 2: Configure SSH Server
Edit SSH Configuration File: The SSH server configuration file is usually located at /etc/ssh/sshd_config. Open it with a text editor.
BASHsudo vi /etc/ssh/sshd_config
Ensure SSH Service is Enabled: Look for the line PermitRootLogin and set it to no to disable root login if it's not already set. This enhances security by preventing direct root logins:BASHPermitRootLogin yes
Allow SSH Access for Users: If you want to allow SSH access to specific users (besides the root user), add or verify that AllowUsers is set correctly:BASHAllowUsers username1 username2Replace username1, username2, etc., with the actual usernames you want to allow.
Save and Close the File: After making any changes, save the file and exit the text editor.
Step 3: Restart the SSH server
BASHsystemctl restart sshd
service sshd restart
That’s it! With the new line added and the SSH server restarted, you can now connect via the root user.
Conclusion:
Enabling SSH on Linux involves configuring the SSH server, ensuring necessary firewall rules are in place, and testing the connection. By following these steps, you can securely access and manage your Linux system remotely. SSH provides a robust way to administer servers and transfer files, making it an essential tool for system administrators and developers alike. Remember to keep your SSH configuration secure by disabling root login and restricting access to authorized users only.Frequently asked questions
Which setting allows root to log in over SSH?
Set
PermitRootLogin yes in /etc/ssh/sshd_config and restart the service with systemctl restart sshd. PermitRootLogin no blocks root logins, and prohibit-password allows root only with SSH keys.Is it safe to allow root login over SSH?
It's acceptable on a lab or internal VM. On servers reachable from the internet, log in as a normal user and use sudo, or at least use
PermitRootLogin prohibit-password with key-based login.I changed the file but root still can't log in. Why?
sshd uses the first value it finds for each setting, so check for another PermitRootLogin line, including in files under /etc/ssh/sshd_config.d/. Also, if AllowUsers is set, only the listed users can log in, so add root to it.
How do I check the configuration before restarting sshd?
Run
sshd -t as root. It prints nothing if the file is valid, or the line with the error, so a typo doesn't lock you out.
Comments
0Please sign in to leave a comment.
No comments yet
Be the first to share your thoughts!