# Creating a Root User with "pw"



## Orige (Jul 26, 2010)

Hello!

I'm doing a script for add a user with privileges of root.

I can do this using adduser command and after editting this user with vipw.
I put uid 0 and gid 0 and works fine, but how can I do this with just one command?

pw useradd -n test ....

I tried .:
pw useradd -n test -u 0 -g 0 ...

and do not worked.

Thanks a lot!


----------



## SirDice (Jul 26, 2010)

Why can't you use sudo or su to give someone root access?

There's no need to create more then one root account.


----------



## Orige (Jul 26, 2010)

Hello.

Is a Test Script for a Test Server.
Sudo isn't necessary.


----------



## anomie (Jul 26, 2010)

@Orige: if you legitimately _need_ to be root for an operation, then be root. If you need to run a subset of specific commands as a different user (including root), then use security/sudo.

I don't know of a problem that creating a user "with privileges of root" solves. Perhaps you could enlighten us.


----------



## Orige (Jul 26, 2010)

Hello @anomie!

For me, sudo isn't necessary for THIS server.
Sudo was implemented on another servers , but i wanna know how can I add any user with uid 0 and group 0 with just one command pw.

I can do this editing the user in vipw.

This is it, curiosity.


----------



## anomie (Jul 26, 2010)

What I am getting at is: don't do that. If you have a legitimate reason to do that, please explain yourself. There may be a better solution to the problem.

-------

I don't see anything syntactically wrong with the pw(8) command you attempted, BTW. Some programs have hard coded restrictions to prevent you from doing something dangerous. (I am not saying that is the case here, but I've seen that sort of thing before.)


----------



## Orige (Jul 26, 2010)

I will read pw man page and do my tests, after that , I'll put the command here.

Thanks a lot


----------



## fronclynne (Jul 27, 2010)

*Don't drink & admin, you might type -f and lose everything.*

To quote pw(8)

```
It is possible to use useradd to create a new account that duplicates an
     existing user id.  While this is normally considered an error and will be
     rejected, the [B][color="Red"]-o[/color][/B] option overrides the check for duplicates and allows the
     duplication of the user id.
```

(& I did test it, you can in fact create a user with uid 0, which is still a terrible idea)
	
	



```
# pw useradd -n test -u 0 -g 0 -o
pw: WARNING: new account `test' has a uid of 0 (superuser access!)
```


----------



## Orige (Jul 27, 2010)

Great!
This is it!

So, I forgot this parameter -o, but I was almost there.
This Still a terrible  idea but my curiosity is over.

Thanks a lot!


----------

