24

I have just started to use Scientific Linux (7.0) (although I assume this question might be distribution neutral..). The kernel version is 3.10.0-123.20.1.el7.x86_64.

Coming back to my question.

I switched to root account and from there created an new user account test-account using the command adduser test-account. It didn't prompt me for a password neither did I use the option to provide password. So I guess it's a "without password" account. I can login into this account from root account - which I suppose I'd be able to without providing password even if the test account had a password. However when I try to login into this(test-account) from a third account - it prompts me for password. And just pressing Enter doesn't work.

Is it possible to login into this account from a non-root account. Is there a way (without switching to root or using sudo) ?

  • Your system's policy could be, that a password is required. adduser knows the -p option to set a password, tho its use is not recommended. So as root, do passwd test-account and set a password. – ott-- Mar 27 '15 at 18:41
  • no, the account is created without password and I'm even able to access it by switching to it from root. only thing I'm not able to do it is to switch to it from a normal user. – Lavya Mar 27 '15 at 18:58
  • How do you switch to it from root (what command are you using)? – roaima Mar 27 '15 at 19:40
  • @roaima su test-account. That switches to the test-account without a password prompt (which is what would happen even if test-account had a password). However, when I try to switch to test account from anther non-privileged user account, kernel asks me for the password with a prompt, and it doesn't accept void (pressing eneter) – Lavya Mar 28 '15 at 6:59
  • You've already received the answer to this. Enjoy. – roaima Mar 28 '15 at 7:52
27

By default on enterprise GNU/Linux and it's 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:::

the reason for this is 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.
  • "the adduser command creates a user which is disabled until you explicitly specify a password for that user": how am I able to switch to test-account from root if that is the case (user being disabled)? – Lavya Mar 27 '15 at 18:55
  • su test-account – Nathan McCoy Mar 27 '15 at 18:58
  • I meant to ask is that if the account is disabled, then how is it that I'm able to switch to it using su from root? – Lavya Mar 27 '15 at 19:09
  • 2
    the root user can su into any account that has a shell. If the shell was set to /bin/false for example, it would not work. It is just the magic of root! many user accounts do not have a valid shell, and are only used to execute specific programs as that user. such as the apache user and the apache webserver. – Nathan McCoy Mar 27 '15 at 19:15
  • In Ubuntu 18.04, I can't login as the user with empty password. – Ciro Santilli 新疆改造中心法轮功六四事件 Oct 3 '18 at 12:03
3

I have user guest which is passwordless. This is its record:

guest:U6aMy0wojraho:17057:0:99999:7:::

The string "U6aMy0wojraho" is the hashed password of the guest user. When I log in I simply hit enter for the password and the system allows me in.

You should edit the file /etc/shadow and add the above mentioned string right after the username and the first colon.

I copied this string from Ubuntu live CD - its user is paswordless.

  • Instead of the accepted answer (passwd -d ...) this additionally works with sddm. – mzimmer Jan 15 '18 at 10:05
  • 1
    Editing the /etc/shadow file directly is risky and usually not recommended. Having a guest account it fine, but using the tools to edit the password will reduce potential improper user input or issues with multi-user file saves. – Nathan McCoy Jun 27 '18 at 7:04
  • @NathanMcCoy, I agree that it is risky. But GUI tools do not allow to make empty password - it requires at least 6 or 8 characters. At least, this is the case on Kubuntu that I use. – Raicho Nikolov Jul 10 '18 at 13:07
  • @NathanMcCoy yes, one could use chpasswd -e to do that more safely: unix.stackexchange.com/a/472966/32558 – Ciro Santilli 新疆改造中心法轮功六四事件 Oct 3 '18 at 12:10
  • This is great for emergency recovery cases, plug in the hard drive (so to speak) and edit a couple files to fix the machine. Specifically add this user and add him to sudoers temporarily then use a serial console to login and fix whatever broke openssh – Ray Foss Mar 27 at 15:16
2

User with empty password

sudo useradd test-user-0
echo test-user-0:U6aMy0wojraho | sudo chpasswd -e
su test-user-0

The password prompt still shows unfortunately.

But if you just hit enter without typing anything, and it logins as the user test-user-0.

The -e flags tells chpasswd that the password is already encrypted, and U6aMy0wojraho is the hash of the empty string.

Tested on Ubuntu 18.04.

BusyBox autologin

On the terminal at least, you don't need to create an user without a password to allow someone to not type their passwords everytime, hacking inittab a bit is enough: How to login automatically without typing the root username or password in Buildroot BusyBox init?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.