Tuesday, April 14, 2009

Manage users in Ubuntu

Ubuntu includes a nice graphical tool for adding and managing users. This is also possible through the use of the command line. This is the only method for servers without a GUI installed. Ubuntu has two ways to add a user, one walks you through the process and the other is a bit more basic. Here's how they work:
sudo adduser [name]
This will setup a new user named [name] with the default settings, including a home directory located at /home/[name]. After setting this up, you will be prompted to enter a password for the new user. The other way is more inline with standard *nix commands:
sudo useradd -m -s /bin/bash [name]
sudo passwd [name]
The -m flag of the useradd command creates the home directory and the -s flag specifies the login shell to use. If you leave this off, the shell it will use is /bin/sh. Instead of using the passwd command to set the password for the user, you could add the -p flag to the useradd command and specify the password to be used then. This, however, means that the password will be written in clear text for anyone looking over your shoulder to see and it is not displayed with the passwd command.

Users can be removed using this command:
sudo userdel -rf [name]
Using the -rf flags will force the removal of the home directory. If you want to retain the files contained there, leave this off.

In Ubuntu, the first user created upon installation is automatically added to the admin group with access to sudo power. Subsequently added users will not be in this group and so will not have sudo power. If you want your other users to be limited users, this is great. If you want to have another user with administrator power, use this command:
sudo usermod -aG admin [name]
This will append admin to the list of a user's groups. The next time this user logs in they will receive a notification of how to use the sudo command. There are other uses for the usermod command. The -s flag, for example, will change the user's login shell.

For more details on these commands, check out the manual pages:
man adduser
man useradd
man userdel
man usermod

No comments:

Post a Comment