This tutorial will show you how to Enable SSH and Root Login in Linux for Remote Access.
Step 1: Capture the IP address through the terminal (refer to the screenshot below).
Tip: To find your machine’s IP address, use the command:
$ ifconfig
Step 2: Launch the PuTTY application, enter the <IP address>, and select the connection type as SSH (refer to the screenshot below).
Step 3: If SSH is not enabled, you will see the following error message in PuTTY:
---------------------------
PuTTY Fatal Error
---------------------------
Network error: Connection refused
---------------------------
OK
---------------------------
By default, the root account is disabled for direct SSH due to security restrictions. Enabling root account is at your own risk.
Step 4: Enable the SSH daemon on the guest operating system.
To check if the SSH service is enabled or disabled, use the following command:
$systemctl status ssh
To start the SSH service, execute the following command:
Tip: To know the current logged-in user, execute:
$ whoami
Note: To start any daemon, sudo permissions are required. Use the command below:
$ sudo systemctl start ssh[sudo] password for itadmin: <Enter itadmin credentials>
To enable SSH to start automatically on every reboot, execute the following command:
$ sudo systemctl enable ssh
Step 5: Now, try logging in with the root account using PuTTY. Unlike in Step 3, this time you will see an "Access Denied" error. This is a good sign, as it indicates that port 22 is responding to the machine. However, we still need to resolve the access denied error.
Error: Root access denied
The itadmin account can SSH into the Linux system. From the itadmin account, you can switch to the root account (refer to the screenshot), but if you still need direct SSH access, follow Step 6.
Tip: To switch from the current user to root, execute the following command:
$ suPassword: <Enter the root account password>
Step 6: To permit direct root login for the root account, execute the following command:
Tip: Open the following file using the vi editor and add PermitRootLogin yes under the #Authentication section (refer to the screenshot):
$ vi /etc/ssh/sshd_config
Tip: Press the i key on the keyboard to insert a new line:
PermitRootLogin yes
To save the changes: Press the ESC key, then type :wq! (refer to the screenshot).
If you want to exit without saving the file: Press the ESC key, then type :q! to exit without saving.
Once the configurations are successfully saved, you need to restart the SSH daemon.
To roll back or disable SSH access for the root account, simply comment out the line by adding a # (pound sign) before PermitRootLogin yes, like this:
# PermitRootLogin yes
To restart the SSH daemon, execute the following command:
$ systemctl restart ssh
Tip: Verify the SSH daemon status with the command:
$ systemctl status ssh
Step 7: Exit PuTTY and try to SSH using the root account. Refer to Step 2 for instructions on how to SSH.
“Information is power. But like all power, there are those who want to keep it for themselves.”
― Aaron Swartz
I hope this information is useful for you. Please forgive any typos or incomplete sentences.
Thanks for Visiting vNetes.com