Adding / deleting new users under Debian
Adding new users is something that you will need to do if you want to allow other users to use your machine.
To add a new user is simple enough. First of all you need to become root, you can do this by logging in with your normal user account then running the
Once you are root you can add a new user with the adduser command, this needs a single parameter – the name of the account to add.
If you want to give the user ‘John Smith’ a login account you could run
Once this is done there are two more things you need to do – set the password for this account (they can change it themselves later) – you can do this by running
When you run passwd it will ask you for the password to set twice, to make sure you’ve typed what you think you’ve typed.
The next thing you need to do is make a home directory for them. This will normally just involve running:
mkdir /home/jsmith chown jsmith:users /home/jsmith
This creates a directory with the same name as the login account beneath the
directory – then changes it to be owned by the user.
If you omit the ‘
‘ command the user will not have permission to save files inside their own home directory !
Now let us test :
A simplified expression of the syntax of the su command is:
su [options] [commands] [-] [username]
The square brackets indicate that the enclosed item is optional. Thus, the simplest way to use the su command is to just type:
The operating system assumes that, in the absence of a username, the user wants to change to a root session, and thus the user is prompted for the root password as soon as the ENTER key is pressed. This produces the same result as typing:
If the correct password is provided, ownership of the session is changed to root.
Likewise, to transfer the ownership of a session to any other user, the name of that user is typed after su and a space. For example, to change the owner of the current login session to a user named alice, type the following:
The user will then be prompted for the password of the account with the username John Smith.
Debian / Ubuntu
On Debian or Ubuntu systems, useradd is a command itself, and you can create users and define options to them using this command, and adduser is a perl script, that uses useradd to create the account, asking you the password, Full-name, phone and others like this:
ggarron@debian:~/tmp$ sudo adduser test Adding user `test' ... Adding new group `test' (1004) ... Adding new user `test' (1003) with group `test' ... Creating home directory `/home/test' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for test Enter the new value, or press ENTER for the default Full Name : gasf Room Number : asdg Work Phone : asdf Home Phone : asdf Other : asdf Is the information correct? [Y/n] y
As you can see the script will do the job for you, I prefer using the command itself, as I like to have the control, but is up to you which one to use.
to remove a user and their home directory, use:
sudo deluser -remove-home <user-name>
to remove all of their files on the server:
sudo deluser -remove-all-files <user-name>