Temporarily enable SSH password authentication on RHEL/Centos VMs.

To enable password based authentication on RHEL/Centos machines, login as root to the target host. ( sudo the commands below if you are not logging in as root)

1. Create the password authenticated user if not already created –

  • On console run : adduser [username]
  • Set a password for the new user: passwd [username]

2. Add the user to sudoers and enable remote login –

  • On console run: visudo
  • In the file opened for editing, comment out the line – “Defaults    requiretty
  • Add the line “[username] ALL=(ALL)       ALL”  below the line “root ALL=(ALL)       ALL

3. Enable password authentication for SSH.

  • vi /etc/ssh/sshd_config
  • Replace the line “PasswordAuthentication no” with “PasswordAuthentication yes“. (Uncomment this line if commented.) Save and close this file.
  • /etc/init.d/sshd reload

4. To disable password authentication after use, in the above file replace “PasswordAuthentication yes” with “PasswordAuthentication no“; reload sshd as before.

Sreekumar Kj
Sreekumar (KJ) has been a hobby programmer from school days. Codemarvels is his personal blog from the year 2010, where he writes about technology, philosophy, society and a bit about physics. He now runs a conversational AI company - DheeYantra - focusing his efforts to help businesses improve operational efficiency using digital employees powered by AI.