Linux add user without password

How to create a user without password in Linux

This article title may sound awkward to you, but it’s useful. You may ask, why would we want to create a user without a password. I thought that too, but my friend faced this question in one of the interviews.

So, I want to share this with users who are looking for an answer to this question. Practically it may not be useful, but you should know the answer.

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

What is passwd command?

The passwd command is one of the most frequently used command by Linux administrator’s to update users’ authentication tokens in the /etc/shadow file by calling the Linux-PAM and Libuser API’s.

What is useradd command?

Linux is a multi-user operating system that allows more than one user to interact with the system at the same time. The “useradd” command is used to create new user accounts. When executed, “useradd” command creates a new user account as per the options specified in the ‘/etc/default/useradd file’ & ‘/etc/login.defs’ file.

Now let’s delve into some of the methods used to create a user account without password:

Method-1: Creating a user without password 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 as shown in the example below.

Note: we can use the commands “useradd” or “adduser” interchangeably to create a user in Linux.

useradd is native binary compiled with the system. But, adduser is a perl script which uses useradd binary in back-end. adduser is more user friendly and interactive than its back-end useradd. There’s no difference in features provided.

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

Details:

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

Method-1.a: Using passwd comamnd

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

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 saying “Access denied”.

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

Method-2: Creating a user without password 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:

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.

Details:

  • -e or —encrypted Supplied passwords are encrypted

Method-3: Creating a user without password 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.

Details:

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

Method-3.a: Using /sbin/nologin shell

User account can be created with the /sbin/ nologin shell option. This shell usually does not allow the user to log in to the computer.

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

Details:

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

Method-3.b: Changing the shell to false

We can use the /bin/false option with the “useradd” command to create a new user without password. ‘/bin/false’ is just a binary that immediately exits, returning false, when it’s called. The user logs in and immediately sees the login prompt again.

Читайте также:  Linux смена права доступа

This shell works exactly like the one above, and it does not allow the user to log in to the computer.

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

Method-3.c: Changing the shell to /dev/null

‘/dev/null’ is a simple device which is implemented in software and doesn’t correspond to any hardware device on the system.

dev/null looks empty when you read from it, whereas data written to this device simply “disappears.”

User can be disabled by changing the shell to /dev/null as shown below:

Closing Notes

You learnt different ways to create a user without a password in Linux.

If you found this article helpful, please do share with your friends and spread the knowledge. Please feel free to comment below if you have any queries/concerns. We will get back to you as soon as we can. Happy learning!

Источник

Can I set my user account to have no password?

If I attempt to change my password to nothing by opening «User Accounts», the «Change» button remains greyed out:

How do I change my password to be empty? I know you can set Ubuntu to automatically log you in, but I want my password to be empty, I never want to type in a password to authenticate myself as that user.

I know that there are reasons why this might not be a good idea, but I want to know if it is even possible. I’m using Ubuntu 12.10.

6 Answers 6

You can’t do that using the GUI tool, but you can using the terminal.

First, if your user has sudo privileges, you must enable its NOPASSWD option. Otherwise, sudo will ask for a password even when you don’t have one, and won’t accept an empty password.

To do so, open the sudoers configuration file with sudo visudo , and add the following line to the file, replacing david with your username:

Close the editor to apply the changes, and test the effect on sudo in a new terminal.

Delete the password for your user by running this command:

If you ever get prompted for a password, just type enter and it should work. I’ve tested this answer with LightDM, the lock screen, sudo , gksu and it works, but there’s one more step to get it to work with pkexec (thanks muru).

Warning: Be careful once you remove your password using this method, you won’t be able to authenticate yourself to prove you have admin rights, in a GUI or in the terminal (like installing an application using Synaptic, or using sudo through the command-line). This is because of bug #1168749.

Only do this if the user is not the only admin user.

This has been tested on Ubuntu 12.04 and 12.10.

Make sure that you click on Unlock to be able to accomplish the tasks below:

Go into user accounts, and click on the password field:

Once the window opens, click on the down arrow to the right of «Action».

and change it to «Log in without a password», and then click on «Change»:

Optionally, you can also enable automatic log-in, like this:

To give the user a password again after running this procedure, you can’t use a GUI (bug #882255), you have to use the command-line:

Log in as another user with admin priveleges. (Remember, the original one cannot run with admin privileges without a password using this method.)

Run the following in a terminal:

Again, I must warn you that once you remove the password, you won’t be able to authenticate yourself in the GUI or a terminal, like installing an application using Synaptic, or using sudo on the command-line.

I think it’s possible to do this, but will get you into trouble once you try to install updates or anything else that requires sudo; as you need an account with sudo access (and a password) in order to install.

Your best options seem to be:

  • Use the Guest account that doesn’t have a password. Thereby leaving a default account with password.
  • Hellbent on an account without password? Strongly recommend not doing this: Add a new user account (with password), then change it to be the equivalent as blank. To do this:
    1. create a user (either via GUI or useradd, etc). Then,
    2. CTRL — ALT — T to open terminal. Next,
    3. gksu gedit nano -B /etc/shadow then find the new user and change the existing password hash with: U6aMy0wojraho — so it looks something like: newuser:U6aMy0wojraho:13996:0:99999:7.

Best solution to your question: Choose to automatically log in your account, which is likely the main benefit you’re after. to do this:

press CTRL — ALT — T (to open terminal). In Terminal, type:

replace YOURUSERNAME — with an actual username on your system.

Источник

Creating a user without a password

I’m trying to create a user without password like this:

It’s created fine. But when I try to login under the git user I’m getting the password entering:

When I leave it empty I get an error:

6 Answers 6

The —disabled-password option will not set a password, meaning no password is legal, but login is still possible (for example with SSH RSA keys).

To create an user without a password, use passwd -d $username after the user is created to make the password empty. Note not all systems allow users with empty password to log in.

You’ve created a user with a “disabled password”, meaning that there is no password that will let you log in as this used. This is different from creating a user that anyone can log in as without supplying a password, which is achieved by specifying an empty password and is very rarely useful.

In order to execute commands as such “system” users who don’t log in normally, you need to hop via the root account:

If you want certain users to be able to run commands as the git user without letting them run commands as root, set up sudo (run visudo as root and add a line like %gitters ALL = (git) ALL ).

If you want to access the system under the git user you should use sudo:

Create an user with empty password

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.

Terminal autologin with getty -a

On the terminal at least, you don’t need to create an user without a password to allow someone to not type their passwords every time.

So I believe that it should not be very hard to adapt that technique by modifying Ubuntu 18.04’s systemd init system scripts to setup a getty -a terminal as mentioned in that answer, although I haven’t tried to do it myself.

Источник

How to automatically add user account AND password with a Bash script?

I need to have the ability to create user accounts on my Linux (Fedora 10) and automatically assign a password via a bash script(or otherwise, if need be).

It’s easy to create the user via Bash e.g.:

Is it possible to assign a password in Bash, something functionally similar to this, but automatically:

19 Answers 19

You could also use chpasswd:

so, you change password for user username to new_password .

You can run the passwd command and send it piped input. So, do something like:

I was asking myself the same thing, and didn’t want to rely on a Python script.

This is the line to add a user with a defined password in one bash line:

-s /bin/bash , -m Crates home directory, -s specifies users defualt shell, substitute password and user for your needs.

The code below worked in Ubuntu 14.04. Try before you use it in other versions/linux variants.

I liked Tralemonkey’s approach of echo thePassword | passwd theUsername —stdin though it didn’t quite work for me as written. This however worked for me.

-e is to recognize \n as new line.

sudo is root access for Ubuntu.

The double quotes are to recognize $ and expand the variables.

The above command passes the password and a new line, two times, to passwd , which is what passwd requires.

If not using variables, I think this probably works.

Single quotes should suffice here.

The following works for me and tested on Ubuntu 14.04. It is a one liner that does not require any user input.

Taken from @Tralemonkey

Single liner to create a sudo user with home directory and password.

You can use the -p option.

Unfortunately, this does require you to hash the password yourself (where passwd does that for you). Unfortunately, there does not seem to be a standard utility to hash some data so you’ll have to write that yourself.

Here’s a little Python script I whipped up to do the encryption for you. Assuming you called it pcrypt, you would then write your above command line to:

A couple of warnings to be aware of.

  1. While pcrypt is running, the plaintext will be visible to any user via the ps command.
  2. pcrypt uses the old style crypt function — if you are using something more moderns like an MD5 hash, you’ll need to change pcrypt.

Источник

How to run sudo command without a password on a Linux or Unix

I ‘m a new Unix system user. How do I use sudo command without a password on a Linux or Unix-like systems? I log in as tom@my-cloud-server-ip and disabled root login for ssh. After login, I need to run some commands as root user. I am the only sysadmin using my server. How do I run or execute sudo command without a password for a user named Tom under Debian/Ubuntu/CentOS Linux cloud server?

sudo (“superuser do”) is nothing but a tool for Linux or Unix-like systems to run commands/programs as another user. Typically as a root user or another user. You can delegate common tasks such as reboot the server or restart the Apache or make a backup using sudo for unprivileged users. By default, sudo needs that a user authenticates using a password before running a command. Some times you may need to run a command with root privileges, but you do not want to type a password using sudo command. This is useful for scripting or any other purpose. This can be achieved by editing /etc/sudoers file and setting up correct entries. You need to consider any security consequence of allowing a sudo command execute without a password.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements sudo on Linux or Unix/BSD/macOS
Est. reading time 3 mintues

NOTE: Initial setup must be done using the root account. One can gain root access by directly log in as root using console, ssh, or su command:
su —
In all cases, you must know the root password in advance before sudo can be configured to commands without a password. You might have sudo access and grant another user account passwordless access for commands.

How to to run sudo command without a password:

  1. Gain root access: su —
  2. Backup your /etc/sudoers file by typing the following command:
    cp /etc/sudoers /root/sudoers.bak
  3. Edit the /etc/sudoers file by typing the visudo command:
    visudo
  4. Append/edit the line as follows in the /etc/sudoers file for user named ‘vivek’ to run ‘/bin/kill’ and ‘systemctl’ commands:
    vivek ALL = NOPASSWD: /bin/systemctl restart httpd.service, /bin/kill
  5. Save and exit the file.

How do I execute ALL sudo commands without password?

Type the following command as root user:
# visudo
Or if you have sudo access and want to grant another user permission, try:
$ sudo visudo
Append the following entry to run ALL command without a password for a user named tom:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Here is my sample config file:

Fig.01: How to execute sudo without password for tom user

How do I test it?

Simply run /bin/kill to kill any process without a password:
[vivek@server ]$ sudo /bin/kill pid-here
OR
[vivek@server ]$ sudo /bin/systemctl restart httpd.service

Conclusion

You learned how to run a command without a password when using sudo on Linux or Unix-like systems. There is a significant security risk associated with passwordless operations. Hence, I would strongly recommend NOT doing this, but as they say, “it is not UNIX’s job to stop you from shooting your foot. If you so choose to do so, then UNIX’s job is to deliver Mr. Bullet to Mr. Foot in the most efficient way it knows.” For more info read man pages:
visudo(8)

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Читайте также:  Как узнать последние ошибки windows
Оцените статью