I am assigned to generate a script that can disable password login for ssh service. Knowing that I can perform this action by editing /etc/sshd_config file, but my mentor mentioned the file I should look into is /etc/password file. That was the hint for me to perform this task. Here is what I did, I removed the 'x' symbol in the user. I believed the field is reserved for hashing password.
The original
pi:x:1000:1000:,,,:/home/pi:/bin/bash
After edited:
pi::1000:1000:,,,:/home/pi:/bin/bash
The result: Without the key I'm stuck with retyping the pass window.
Updated for clarity: The script should be used to reply on public and private key in order to login to the pi server. To put it another way, I try go for password-less login, making it a feature to harden security.
/etc/passwdempty is a dangerous method that relies on your PAM configuration (or a setting in/etc/ssh/sshd_configor in some other login method that won't use PAM) disabling network/remote logins for passwordless accounts. After your edit, try logging in on the console as userpi: you may find out that you can get in with just pressing enter at the password prompt. It's safer to set the password field to an invalid value like*, as suggested by @MatthewGauthier above./etc/shadowfile to determine the password. If the field is "*" (or anything that isn't an encrypted password), logins via password will never work. If the field is empty, then unless some other mechanism prevents it, anyone can log in to the account without providing any password at all., the exact opposite of what you want to accomplish.sudo vipwand changing the field to "*" will effectively disable logins via password, regardless of the method used (ssh, rlogin, etc.).