Thursday, July 30, 2009

adding users in Ubuntu

Add a User on Ubuntu Server
Ubuntu Server is like any Linux variety, and has full multi-user capabilities, and a common task on any server is adding users.

useradd

The useradd command will let you add a new user easily from the command line:

useradd <username>

This command adds the user, but without any extra options your user won’t have a password or a home directory.

You can use the -d option to set the home directory for the user.
The -m option will force useradd to create the home directory.
We’ll try creating a user account with those options, and then use the passwd command to set the password for the account.

You can alternatively set a password using -p on the useradd command,
but I prefer to set the password using passwd.

sudo useradd -d /home/testuser -m testuser
sudo passwd testuser

This will create the user named testuser and give them their own home directory in /home/testuser. The files in the new home directory are copied from the /etc/skel folder, which contains default home directory files. If you wanted to set default values for your users, you would do so by modifying or adding files in that directory. If we take a look at the new home directory for the user:

jerome@krymz-laptop:/etc/skel$ ls -la /home/testuser
total 20
drwxr-xr-x 2 testuser testuser 4096 2006-12-15 11:34 .
drwxr-xr-x 5 root root 4096 2006-12-15 11:37 ..
-rw-r–r– 1 testuser testuser 220 2006-12-15 11:34 .bash_logout
-rw-r–r– 1 testuser testuser 414 2006-12-15 11:34 .bash_profile
-rw-r–r– 1 testuser testuser 2227 2006-12-15 11:34 .bashrc


You’ll notice that there are bash scripts in this directory. If you wanted to set default path options for all new users, you would do so by modifying the files in /etc/skel, which would then be used to create these files by the useradd command.

adduser

The adduser
command is even easier than the useradd command,
because it prompts you for each piece of information.
I find it slightly funny that there are two virtually identically named commands that do the same thing, but that’s linux for you.

Here’s the syntax:

adduser <username>


Example:
jerome@krymz-laptop:/etc/skel$ sudo adduser zionuser:
Adding user `zionuser’…
Adding new group `zionuser’ (1004).
Adding new user `zionuser’ (1004) with group `zionuser’.
Creating home directory `/home/zionuser’.
Copying files from `/etc/skel’

Enter new UNIX password:
Retype new UNIX

password: No password supplied

Enter new UNIX password:
Retype new UNIX password:

passwd: password updated successfully

Changing the user information for zionuser

Enter the new value, or press ENTER for the default

Full Name []: zioner

Room Number []: 0

Work Phone []: 555-1212

Home Phone []: 555-1212

Other []:

Is the information correct? [y/N] y

No comments:

Post a Comment

About

Blogger templates