Linux - Users and groups

From XennisWiki
Jump to: navigation, search

User and group management on Linux distribution operating system

Users

Change owner of a file (chown)

Change the ownership of a file (the option -R is for recursive change)

chown [-R] <owner-user>:<owner-group> <file-or-dir>

List all users

Use cut to list all users

cut -d: -f1 /etc/passwd

Root user

On a Ubuntu system your user account has access restrictions. The user with all rights is named root. Hence it's a kind of an administrator. Root rights are often needed, for instance to install a program.

To execute a command with root rights, just use the sudo (super user do) in front of the command

sudo <command>

Open a file (in this case with vim) with root rights

sudo vim <file-name>

Change the default editor, e.g. for visudo

Enter the command to list all editors and next type the number of the editor to use

update-alternatives --config editor

Delete a user

Delete a user (-r and the user's home directory)

userdel [-r] <user-name>

Groups

Change group of a file (chgrp)

Every file has a owner and a (owner) group. To change the group of a directory recursively

chgrp -R <group-name> <directory-name>

Add a user to a group

Use gpasswd or usermod

gpasswd --add <user-name> <group-name>
usermod -a -G <group-name> <user-name>

Delete a user from a group

gpasswd -d <user-name> <group-name>

Delete a group

groupdel <group-name>

Change the access of a directory

Change the access of a directory recursively for a group to read, write and execute:

setfacl -m group:<group-name>:rwx -R <directory-name>

Output users of a group

Use for instance grep

grep '<group-name>' /etc/group

See also