# adduser command



## amr (Jan 3, 2021)

Hello,
What I am trying to achieve is to create a user with `pw` instead of the an interactive methon `adduser`.

```
Username   : odoo
Password   : <disabled>
Full Name  : Odoo ERP
Uid        : 1002
Class      :
Groups     : odoo
Home       : /home/odoo
Home Mode  :
Shell      : /bin/sh
Locked     : no
```

I read pw() and adduser() so came to this

```
pw adduser odoo -d /home/odoo -s /bin/sh -c "Odoo ERP" -w no
```
But I failed.

The main point is how I can make "Password   : <disabled>" by `pw`

Any idea, please


----------



## amr (Jan 3, 2021)

I made it by adding -m


```
pw adduser odoo -d /home/odoo -s /bin/sh -c "Odoo ERP" -m -w no
```


----------



## ralphbsz (Jan 3, 2021)

amr said:


> But I failed.


What happened? What went wrong? What was the error message?

I can't debug "I failed". I can try to debug a concrete problem.



> The main point is how I can make "Password   : <disabled>" by `pw`


Read "man pw". It is described in there. Look at the "-h" option.



amr said:


> I made it by adding -m


Strange. Above you said the problem was making the account disabled. Now you solved the problem of the new user not having a home directory. I'm confused. But happy that it worked.


----------



## amr (Jan 3, 2021)

Hi ralphbsz,
I wanted to disable password authentication only. but I wanted to log using
`# su - odoo` as superuser


----------



## ralphbsz (Jan 3, 2021)

In that case, check the /etc/passwd file (for example with vipw), and make sure the password column is starred out.


----------



## amr (Jan 3, 2021)

`grep odoo /etc/passwd`

```
odoo:*:1002:1002:Odoo ERP:/home/odoo:/bin/sh
```
Is that OK?


----------



## scottro (Jan 4, 2021)

If the user didn't have a home directory, that's because you left out -m. As far as giving the user no password, you can do it by just not setting a password, unless I'm missing something here. You can also set the shell to no login. If the home directory should be /home/odoo than you don't need -d--that's only when using a non-standard directory, say if you were adding a web user and you wanted their directory to be in /usr/home/www/odoo or something.

So, I would think that

```
pw useradd odoo -m
```
 might even be sufficient as it seems the rest are the defaults.  If I do that, I see at the end of /etc/passwd

```
odoo:*:1002:1002:User &:/home/odoo:/bin/sh
```

You could also add -c 'whatever' for the :User &: part such as test user or whatever it is.
You haven't set them a password, so they won't be able to log in.   You can also set their shell to /usr/sbin/nologin. 

I'm not sure if I've misunderstood your question though.


----------



## ralphbsz (Jan 4, 2021)

amr said:


> `grep odoo /etc/passwd`
> 
> ```
> odoo:*:1002:1002:Odoo ERP:/home/odoo:/bin/sh
> ...


I don't know. Let's try to figure it out. "man 5 passwd" ... oh wait. You know why I just did "man 5 passwd", right? If not, learn about Unix and how to get help yourself.

Proceeding swiftly: "man 5 passwd" says that the colon delimited fields are name, encrypted password, uid, gid, gecos (which in reality is the cleartext user name), home directory, and login shell. To be honest, the man page is a little confusing: It first discusses some other fields (which are present in master.passwd but not in passwd), then tells you that those fields are not there. But in your example, all seem correct.

As scottro already said: if you don't want this user ever to log in, you can change the login shell to /usr/sbin/nologin, and that is an extra layer of security. This would be a good idea.

Personally, I never use programs such as adduser or pw; I just edit passwd and group myself (using vipw), which is easier and safer.


----------

