You can use chpasswd
The chpasswd command administers users' passwords. The root user can
supply or change users' passwords specified through standard input.
Each line of input must be of the following format.
username:password Only root users can set passwords with this command.
Example 1:
echo username:password | chpasswd
Example 2:
Also for security you can pass encrypted password to chpasswd
# Create Password in Encrpyted Form Using below command
# perl -e'print crypt("YourPassword", "salt")' ; echo -e
echo username:cryptedPass | chpasswd -e
By default on enterprise GNU/Linux and its derivatives, the adduser
command creates a user which is disabled until you explicitly specify a password for that user.
Here is an example on CentOS 6.5, which should be the same as Scientific Linux.
$ sudo adduser test
$ sudo grep test /etc/shadow
test:!!:123456:0:99999:7:::
that's because in the /etc/shadow
file, the password field is !!
, as you can see in the example.
Once you run passwd
for this account, it will change the user's password and allow the user to be able to login.
So what you should be able to do is the following to have a user without a password, simply create an account then delete the password.
$ sudo adduser test
$ sudo passwd -d test
Removing password for user test.
passwd: Success
$ su test
$ whoami
test
now any user should be able to use su
and login as the user test
in my example. You will not have to use sudo
to login as the account.
Although this is possible and you can have an account without a password, it is not advised. If you simply set the password for the user, you should be allowed to login.
$ sudo passwd test
[sudo] password for <YOURACCOUNT>:
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Best Answer
Easiest way to do this from the command line is to use the
passwd
command with root privileges.passwd username
From
man 1 passwd
After you set the user password, you can force the user to change it on next login using the
chage
command (also with root privileges) which expires the password.chage -d 0 username
When the user successfully authenticates with the password you set, the user will automatically be prompted to change it. After a successful password change, the user will be disconnected, forcing re-authentication with the new password.
See
man 1 chage
for more information on password expiry.