sudo
and su
are totally different programs. This is how su
works: if you aren't root, it asks for the password of the target (su
bstitute) user. The condition that you haven't yet set password doesn't change this; use passwd
to add a password for the user. If you need to run commands as another user without knowing or giving that user's password, you should use sudo
, instead.
From a security perspective, it is arguably better to set up and use
sudo instead of su
. The sudo
system will prompt you for your own
password – or no password at all, if configured in such a way – rather
than that of the target user (the user account you are attempting to
use). This way you do not have to share passwords between users, and
if you ever need to stop a user having root access (or access to any
other account, for that matter), you do not have to change the root
password, which is an inconvenience to everyone else; you only need to
revoke that user's sudo access.
The sudo
equivalent for su - user
is sudo -u user -s
. If you wish to do this without using your own password, you need to visudo
and add this line to your sudoers
file:
yourusername ALL=(anotheruser) NOPASSWD: /bin/bash
This gives yourusername
permission to run /bin/bash
as user anotheruser
without password.