Short answer
Yes you should enable all your users to use sudo
without using a password. If you don't want to alter the default sudo
group on your distribution you can create another group, as example sudoers_without_password
, and say that this new group and only this one can sudo without password. But in any case, if you are creating users that don't have passwords and should be able to use sudo
, they must be able to use it without passwords.
Long answer
Creating users without passwords that can only login using an SSH public keys using tools like chef, ansible, puppet, etc... is a common practice nowadays and can be considered a quite good practice for a lot of reasons (notably because ssh keys are very secure and managing passwords is both a pain and quite insecure).
Now that you've created all your users you have a small problem: some of these users at least should be able to use sudo and a lot of distributions recommend to use a password to be able to use sudo... but your users don't have a password!
In a perfect world it should be possible for your users to log securely using their ssh keys, then define a password (there is the standard passwd
command for that), then use the sudo command.
Unfortunately we don't live in a perfect world and, should your users try to set a new password using the passwd
, it won't work.
Actually it is possible to make the passwd
command work in this case but it has implications that make it a very bad idea.
It is completely possible to create a user without any password and allow that user to change its own password. The answer is given in this man page. (I won't explain it fully because you shouldn't do it anyway).
Linux systems have two types of users "without a password":
- Disabled users. These users will usually have a
!
or a *
in their /etc/shadow
line. For some reason, disabled users may still login through some means, as example using SSH with private key authentication (at least with most default SSH server configurations). Disabled users are not allowed to set their passwords.
- Passwordless users. The users have nothing as password in their
/etc/shadow
line. These users may change their own passwords.
The problem is that passwordless users are very very discouraged because anyone can login as them. Usually OpenSSH will deny login as one of these users (that's still a thing), but:
- Any other user will be able to use the
su
command to switch to the user even if they are not root or in the sudo group.
- Anyone with a physical access to the machine will be able to log in as the user without password (assuming the machine has a screen, keyboard and mouse).
That's why creating a passwordless user account is heavily discouraged and usually prevented by most automation tools. That is the reason why, when creating your users with chef, it created disabled users instead of passwordless users. Most other similar tools (ansible, puppet, etc...) will do the same because their creators don't want you to shoot yourself in the foot.
So, in order to allow users to log in using SSH with public keys, it's still the best practice to create disabled users, even if that mean they won't be able to create a password for themselves later.
Now back to your "sudo should use a password" problem, in this case there are two best practices that oppose themselves:
- On one hand these users should be disabled users and so they won't be able to change their passwords, because that's how disabled users work. We could create passwordless users instead but that would pose a serious security problem as we've seen earlier.
- One another hand most people consider it's a bad practice to allow users to use
sudo
without inputting a password (sudo may be allowed with or without password depending on the configuration). That is because careless admin users may accidentally input a command with sudo that could have bad consequences.
These two best practice cannot be respected both at the same time, so we have to make a choice. But there is a strong winner here: it's way more dangerous to allow passwordless users than allowing sudo without password.
So, in that case, just configure the sudo
group to allow commands without password, that's the best thing to do anyway as there is no other solution as far as I know.
man sudoers
will yield info about having certain commands being able to run with sudo without user password necessary at all. You can even add a shellscript to /etc/sudoers which would allow a per user "self-password" setting without the need of a prior password.NOPASSWD: ALL
that the team members are part of. If you can suggest a better solution please post it as an answer.