How to Create an User Without Password on Linux

This article title may awkward to you, but it is useful.

You may ask, why would you want to create a user like this?

Yes, I too, but this is what I asked for in an interview some time ago.

So I want to share this with users who are looking for an answer to this question.

It may not be useful when it comes to reality, but knowing this answer is not harmful.

This article shows you how to create a user account without a password or an empty password on Linux.

Method-1: How to Create a User Without Password on Linux Using passwd Command

You can create a user without a password on Linux using the passwd command as follows.

Run the useradd command to create a user account.

# adduser mageshm

Once you have created the user, use the passwd command to remove the user’s password.

# passwd -f -u mageshm
Unlocking password for user mageshm.
passwd: Success

Details:

  • -f or --force Force operation
  • -u or --unlock Unlock the password for the named account (root only)

Method-1a:

Alternatively, you can use the -d option with the password command to remove the password for a user.

# passwd -d magi

Removing password for user magi.
passwd: Success

Details:

  • -d or --delete Delete the password for the named account (root only)

Now, you’ve created a user with “disabled password”. But when you try to access it, it will ask for the password at the same time not allowing you to login.

You might get an error message like “Access denied”.

This is the expected behavior and you will not receive an error message such as “No password, you cannot login”.

Method-2: How to Create a User Without Password on Linux Using chpasswd Command

You can create a user with an empty password on Linux using the chpasswd command.

Run the below command to create a user account.

# adduser mageshm

Once you have created the user, use the below command to remove the user’s password. The -e option expects a hashed password, but you are given a simple password, which is why it is not taken.

# echo "mageshm:pass123" | chpasswd -e

Details:

  • -e or --encrypted Supplied passwords are encrypted

Method-3: How to Create an User Without Password on Linux Using useradd Command

You can create a password-free user on Linux using the useradd command.

The -p option expects a hashed password, but you are provided with a simple password, which is why it is not taken.

# useradd mageshm -s /bin/bash -p 'pass123'

Details:

  • -p or --password Encrypted password of the new account

Method-3a:

Alternatively, use the /sbin/nologin option with the useradd command to create a new user. This shell usually does not allow the user to log in to the computer.

# useradd -s /sbin/nologin mageshm

You will receive the following message when you attempt to switch the account from the root.

# su - mageshm
This account is currently not available.

Details:

  • -s or --shell Login shell of the new account

Method-3b:

Alternatively, use the /bin/false option with the useradd command to create a new user. This shell works exactly like the one above, and it does not allow the user to log in to the computer.

# useradd -s /bin/false mageshm

When you try to switch the account from the root you get nothing.

# su - mageshm

Details:

  • -s or --shell Login shell of the new account

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...