Error when adding new user

Hi,
I ran sudo adduser and then entered all the details for the new user (let's just call the new user username). When I was done I entered yes to 'OK?'
Then, an error came out saying 'adduser: ERROR: There was an error adding user (username)'

I then proceded to try adding user using pw. So, I ran sudo pw useradd username -m -w random.
FreeBSD gave me a randomised password and I logged into username. When I went to the root directory, I could see it didn't have some files like var and media.

I'm just trying to add a new user and give this new user sudo rights. How should I troubleshoot?
 
What was the exact error message?

 
Then, an error came out saying 'adduser: ERROR: There was an error adding user (username)'
Strange. As SirDice said, please give us more details. And please do some debugging: Is the new user in /etc/passwd and /etc/group? Are the UID and GID set reasonably? Does their home directory have the correct ownership and permissions?

When I went to the root directory, I could see it didn't have some files like var and media.
I think you mean to say "I went to the user's home directory", which is probably something like /home/username.

When a new user is created by adduser, the only files that are created in their home directory are those in /usr/share/skel, which are typically shell login configuration, and nothing else. So you should not expect there to be a Media directory. What puzzles me a little bit is that you are expecting there to be var ... that's usually a system-wide directory /var/..., not a per-user thing. Please explain.

I'm just trying to add a new user and give this new user sudo rights. How should I troubleshoot?
One step at a time: let's first debug creating the user, and your expectations for their home directory.

To do what you call "give them sudo rights", I typically add them to the wheel group, so they can use su to become root. Note that I just mixed two things: I'm proposing to let the use su, not sudo. If you want them to use sudo, then edit /usr/local/etc/sudo* appropriate. Slight change of thread topic: These days I don't use sudo any longer, but instead doas. It's easier to use, easier to configure, and just as safe as sudo.
 
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.

So let's get this straight:

First, you tried the $ adduser script. It returned an error message ("ERROR: There was an error adding user (username)") so you resorted to PW(8)

Then you managed to successfully add your new user, or so I understand, but you're now suspicious due to absence of some directories, like /var/ and /media/. Am I correct so far? Good.

  • sudo pw useradd username -m -w random seems to be lacking a -n before the "username"
  • Specify both primary and other groups through -g and -G makes sure of group(s) membership...
  • ...and one may always want to check their ID while they're at it
  • Try $ sudo pw useradd [-n name | -u uid ] -m -g "Primary Group" -G "List of Other Groups"
  • Make sure "wheel" to be listed in the "list-of-other-groups", and that your primary group have the same name and ID that your newly created user.
  • $ sudo visudo ---> that'll open visudo to be edited in your default file editor.
  • Go to the end of the file (how to, depends on which editor you'll use). Near the bottom you'll find two lines alluding to "wheel" group and beginning with a "%", like in common (t)csh prompts. Uncomment that line (i.e. remove the '#' at the beginning).
  • Save and quit.

Your user should be able to use $ sudo now. As for /var/ and /media/, neither is, normally, inside /usr/home/ or /home/, rather being subdirectories at the root (that's what the "/" in /var/ and /media/ means anyway)
 
Back
Top