After doing some security audits of servers, xFusionCorp Industries security team has implemented some new security policies. One of them is to disable direct root login through SSH. Disable direct SSH root login on all app servers in Stratos Datacenter.
Open Three terminals. Ensure you have the passwords ready (usually provided in the lab details).
- App Server 1
ssh tony@stapp01 - App Server 2
ssh steve@stapp02 - App Server 3
ssh banner@stapp03
sudo vi /etc/ssh/sshd_config
# In vi editor, search for the line by typing:
# Press '/' then type 'PermitRootLogin' and press Enter
/PermitRootLogin
# You'll find one of these configurations:
# - #PermitRootLogin yes (commented out, root login allowed)
# - #PermitRootLogin prohibit-password (commented out, password auth disabled)
# - PermitRootLogin yes (active, root login allowed)
# To edit:
# 1. Press 'i' to enter INSERT mode
# 2. Remove the '#' symbol if present
# 3. Change the value to 'no'
# 4. Press 'Esc' to exit INSERT mode
# 5. Type ':wq' and press Enter to save and quit
# Correct configuration should look like:
# PermitRootLogin noCheck for syntax errors:
sudo sshd -tIf no errors are displayed, the configuration is valid.
Apply the changes by restarting the SSH daemon:
sudo systemctl restart sshdConfirm the service restarted successfully:
sudo systemctl status sshdConfirm the change persists:
sudo grep "^PermitRootLogin" /etc/ssh/sshd_configExpected output: PermitRootLogin no
Important: Keep your current SSH session open while testing.
Open a new terminal and attempt to connect as root:
ssh root@stapp01You should receive: "Permission denied" or "Access denied"
Nice on, it works like magic