What do you someone breaks something? I post the solution here...

Kubernetes (K8s/K3d) / Terraform / Ansible / Linux / AWS / Docker / Bash / Python / ELK / CI/CD / Java / Traefik / Nginx / CentOs / Ubuntu


Enable root user on Linux(Ubuntu/RHEL) VM provided by Azure/AWS


1. Login to the Linux machine using Password/Key authentication.

2. Set password for root user and edit sshd_config file using following command. 


   sudo su

   passwd root  -- (Enter password for root user when prompted)

   sudo sed -i 's/PermitRootLogin prohibit-password/#PermitRootLogin prohibit-
   password/g' /etc/ssh/sshd_config

    sudo sed -i 's/PasswordAuthentication no/#PasswordAuthentication no/g'
   /etc/ssh/sshd_config  

   sudo sed -i '$ a PermitRootLogin Yes' /etc/ssh/sshd_config  

   sudo sed -i '$ a PasswordAuthentication yes' /etc/ssh/sshd_config  

   sudo sed -i '$ a   PermitRootLogin without-password' /etc/ssh/sshd_config  

   sudo service sshd restart (for RHEL)

   sudo service ssh restart (for Ubuntu)


 3. Start a new session and login as 'root' user.

2 comments:

loveinabox said...

What if 'sed' command doesn't work?

Shailesh Thakur said...

In that case you have edit the file manually

vim /etc/ssh/sshd_config

comment the lines mentioned below
------------------------------------
PermitRootLogin prohibit-password
PasswordAuthentication no

and then uncomment
---------------------------
PermitRootLogin Yes
PasswordAuthentication yes
PermitRootLogin without-password

if not there add these lines save the file :wq

and the restart the sshd service

sudo service sshd restart (for RHEL)
sudo service ssh restart (for Ubuntu)


https://osgroup-techies.blogspot.in/2017/01/password-less-authentication-on-two.html

Powered by Blogger.