Create a user with no password

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

 

  • 1 utilizatori au considerat informația utilă
Răspunsul a fost util?

Articole similare

SSH login without password

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login...

How to remove a Linux user

How do I drop or remove old users account from my Linux server? I can login using the user’s SSH...

How to restrict and except SSH access to specific IPs

Once your IP is public it gets attention from so many bots in the internet that do brute force...

How to lock and unlock user account in linux

With the help of two commands you can lock and unlock the user account in Linux. To Lock the...

Adding a user to a group

Synopsis This article describes how to add a Linux user (account) to a group. Environment...

Powered by WHMCompleteSolution