We are in the process of migrating this forum. A new space will be available soon. We are sorry for the inconvenience.

How to add a user to Ubuntu


elizabethturner
22-02-2010, 15:17
Nice discussion and information sharing. I learn some new things from here.

Rilly
15-12-2009, 01:33
ah - that explains why i need to always create those files .. i don't use edquota (i can't help it.. i like webmin!)

Myatu
14-12-2009, 20:46
Right, thanks for pointing that out Rilly.

Ubuntu's "edquota" should take care of these files, and the package install for the cronjob. However, if this is not the case (ie., you are using another distro like Centos), here are the additional steps that need to be done before using "edquota" as described above:

Create two files, "aquota.user" and "aquota.group", on the partition where quotas should be enabled. In our case it's "/home":

Code:
sudo touch /home/aquota.user /home/aquota.group
And make sure that these are accessible to root only:

Code:
sudo chmod 600 /home/aquota.*
(Note: "aquota.*" is used with kernel versions 2.4 and up. Otherwise, drop the "a" (quota.user and quota.group).

Remount the /home partition (or alternatively, reboot if the system currently in use by other users):

Code:
sudo mount -o remount /home
And initialize the quota files with:

Code:
sudo quotacheck -vagum
Now you should be able to continue with "edquota" as described earlier.

A word on the cronjob. If you don't have one created as part of the quota package installation, you can do so manually by creating a file "/etc/cron.daily/quota".

Ubuntu's version (as created by the package install):

Code:
#! /bin/sh

# check if quota package is available
test -x /usr/sbin/warnquota || exit 0

# check if warnquota run is configured
test -f /etc/default/quota || exit 0
. /etc/default/quota

if [ "$run_warnquota" = "true" ]; then
        # check if quotas are enabled
        if grep -q '^[^#]*quota' /etc/fstab; then
                /usr/sbin/warnquota
        fi
fi

exit 0
Or in its simplest form (with no soft limit warnings):

Code:
#! /bin/sh
/sbin/quotacheck -avug
Finally, give the file the executable flag and make it read-only to everyone but the owner:

Code:
sudo chmod a+x,go-w /etc/cron.daily/quota

Rilly
14-12-2009, 14:09
you don't need to add the quota.user and the quota.group files using touch?

i.e.
touch /quota.user /quota.group

RapidSpeeds
14-12-2009, 12:31
yeah, Myatu is a smart cookie.

Neil
14-12-2009, 11:39
Done, nice guide.

Halide
11-12-2009, 20:51
Yes certainly needs to be either moved or re posted in How To. The linux noob i am, i could've used this guide about 2 months ago lol

Thanks Myatu!!!!

RikT
10-12-2009, 10:24
ooh this should be in the HowTo section as well i think

nickboi
09-12-2009, 20:29
thanks you sorry my english is bad

thanks

Myatu
09-12-2009, 18:53
He's got Ubuntu 9.10 with the GUI and wants to create a new user that has its own home directory with a 430 Gb hard limit. (that's how I read it )

Well, normally spoken you simply selecting System > Administration > Users and Groups from the GUI. But because NX Client creates a separate session, the "Add User" button might be disabled and you'll have to resort to the command line (CLI).

Select Applications > Accessories > Terminal and type "sudo adduser " for example:

Code:
sudo adduser nickboi
You will first be asked for the root/administrator password. This is for sudo and it will remember it for the next few minutes on subsequent sudo commands. Then it'll execute "adduser nickboi" and ask you additional questions such as the password for this user, full name of this person, etc. It will automatically create a home directory in the form of /home/, so /home/nickboi in the above example.

If you need to remove the user at some point, you can use "sudo deluser ". The /home/ directory will still remain, but this can be removed with common commands ("rm")or through the GUI (desktop).

If you want this user to belong to a particular group, you must make sure the group exists first by using "sudo addgroup ". For example:

Code:
sudo addgroup salesdep
You can then use the command to create a new user, with the addition of the group name, for example:

Code:
sudo addgroup nickboi salesdep
Or you can change the group later (if the user has already been created) with "sudo usermod -G ", for example:

Code:
sudo usermod -G techsupdep nickboi
Limiting the user's space is a bit tricky to setup first time, although OVH may have already done some legwork for you (I don't use OVH's distro, but directly from Ubuntu).

The first thing you need to do is install the user quota package with:

Code:
sudo apt-get install quota
Next you need to edit a particular line in your "/etc/fstab" file. !! Be careful as this is a rather important file and making the incorrect changes could turn your day very sour !! I highly recommend you have a backup available.

First make a copy of the current /etc/fstab file, just in case an error was made:

Code:
sudo cp /etc/fstab /etc/fstab.bak
(You can use the reverse to restore the file, and will work in Rescue Mode).

Code:
gksudo gedit /etc/fstab
Note I used "gksudo" here - same as sudo but with a graphical input for the password -, as well as "gedit", Ubuntu's default editor. If you wish to use another editor, like Nano, simply substitute it.

Find the line that has "/home" in it, for example:

Code:
/dev/hda2       /home           ext3    defaults       0       2
It may look slightly different, but the important thing is that the 2nd column MUST show "/home".

In the 4th column, currently showing "defaults", you need to add ",usrquota,grpquota" so that it will look like this:

Code:
/dev/hda2       /home           ext3    defaults,usrquota,grpquota       0       2
Save the file and exit the editor. Now you should restart the server for the changes to take effect.

From now, you don't have to do all the above again and simply use the "edquota" or "repquota" commands to make changes / view quotas.

I'm a CLI person, so while I'm sure there's some kind of GUI (desktop) app for this, we'll return to the command line (Applications > Accessories > Terminal) to setup a quota profile for the user you've created earlier.

You can edit the quota (the disk space usage limits) with "edquota -u ", for example:

Code:
sudo edquota -u nickboi
It will start your default editor (Nano in most cases, or VI) and allows you to edit the limitations for the user in "blocks". A block is 1 Kbyte, so 1 Megabyte = 1024 and 1 Gigabyte is 1048576 (430 Gigabyte would thus be 430 x 1048576 = 450887680). No limitation is simply 0 (zero).

The first column is the Filesystem (the one associated with "/home" from our previous "/etc/fstab" edit). The second column, "Blocks" is the amount of blocks the user is currently using. Following are the "Soft" and "Hard" limit columns, which you would like to change (the "blocks" described earlier). The last 3 columns are for inodes and I would recommend to leave these alone (leave it at 0).

So in your case, it would look something similar to this:

Code:
Filesystem                   blocks       soft       hard     inodes     soft     hard
/dev/hda2                         0     450887680     450887680          0        0        0
The difference between the "soft" and "hard" limits is at what point the user will be warned that he/she is about to exceed the quota, but still allowed to create files, and at what point the system will refuse any more space to be used. In the above, both are set at the same, but you could decrease the soft limit by something like 1 Gigabyte so the user has a chance to do some cleanup, etc.

Save the file and exit (can be done with the Ctrl+X in Nano, it'll confirm if you wish to save the changes).

There's a grace period for the "soft" limits to be enforced (user warned) and this can be edited using "sudo edquota -t". The "blocks" column is the one you edit and you can use any decimal number followed by "seconds", "minutes", "hours" or "days", for example "10minutes".

If you wish to change the quota for an entire group, as opposed to a single user (see the "addgroup" command earlier), then you can use "sudo edquota -g" instead of "sudo edquota -u ".

To turn quotas off, use "sudo quotaoff -a" and to turn them on, use "sudo quotaon -a"

And finally, to see how much is being used by a user, you can use "repquota -u ".

This seems like a lot of work, but you don't have to do this every single day (it's set and forget). And again, I'm sure there's a desktop app to help you with this, but I'm not aware of one (and someone will undoubtedly suggest one )

I hope this answered your question (and I do hope this was your question! LOL )

Razakel
09-12-2009, 14:39
What exactly do you mean?

nickboi
09-12-2009, 13:40
i got 9.10 desktop but i want to make a usernme on it cos say login by root

and make a username to put 430gb

can someone help me out please

thanks