Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

How to enable Password authentication in Ubuntu 22?

# Step 1: Ensure OpenSSH Server is Installed
sudo apt update
sudo apt install openssh-server

# Step 2: Edit the SSH Configuration File
sudo nano /etc/ssh/sshd_config

# Ensure the following lines are present and uncommented:
# PasswordAuthentication yes
# UsePAM yes

# Ensure these lines are either commented out or set correctly:
# ChallengeResponseAuthentication no
# KbdInteractiveAuthentication no

# Save the file and exit (Ctrl + X, then Y, and Enter)

Also
--------------------------------------------------------------
I realized that a file /etc/ssh/sshd_config.d/50-cloud-init.conf was being referenced in my /etc/ssh/sshd_config, via the following line:

Include /etc/ssh/sshd_config.d/*.conf
this 50-cloud-init.conf file contained the line:

PasswordAuthentication yes
I changed the line to:

#PasswordAuthentication yes
and i restarted the ssh.

Now it is working, I can access only with the ssh key.
--------------------------------------------------------------

# Step 3: Restart the SSH Service
sudo systemctl restart ssh

# Step 4: Verify SSH Service Status
sudo systemctl status ssh

# Step 5: Check PAM Configuration
sudo nano /etc/pam.d/sshd

# Ensure it includes the following lines:
# auth       required     pam_unix.so
# account    required     pam_unix.so
# password   required     pam_unix.so
# session    required     pam_unix.so

# Save the file and exit (Ctrl + X, then Y, and Enter)

# Step 6: Check User Account and Permissions
sudo passwd -u username  # Replace 'username' with the actual username

# Step 7: Test SSH Connection Locally
ssh username@localhost  # Replace 'username' with the actual username

# Step 8: Examine SSH Logs
sudo tail -f /var/log/auth.log

# Step 9: Check SELinux/AppArmor

# For SELinux:
sudo setenforce 0

# For AppArmor:
sudo aa-status
sudo systemctl stop apparmor
sudo systemctl disable apparmor

# Step 10: Ensure No Conflicting Settings in sshd_config
sudo nano /etc/ssh/sshd_config

# Check for match blocks:
# Match User anoncvs
#     PasswordAuthentication no

# Ensure such blocks do not affect the user you are trying to log in with.
# Save the file and exit (Ctrl + X, then Y, and Enter)

# Step 11: Check SSHD Configuration Syntax
sudo sshd -t

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x