3 July 2015

Basic Linux

Users and access levels

The user with the highest level of access is called root and is able to control every process and access every file on the system. Other users can also be given root privileges but this should be done with care.

To create a new user with the name testuser, create a home directory and assign a password:

useradd -m testuser
passwd testuser <insert password>

You can change to the newly created user by using, ask the system who is the current user and return using:

su testuser
whoami
exit

To delete the user and the home directory type:

deluser testuser
rm -R /home/testuser

Users can be also be added to groups, to create a group testgroup, add our newly created user to the group and then delete it:

groupadd testgroup
gpasswd -a testuser testgroup
delgroup testgroup

Permissions

In Linux everything is a file. Every file has a user, a group and a set of privileges rules which determines who can do what. The permissions that can be specified are read (r), write (w) and execute (x). Furthermore every file has different permissions depending if you are the owner (u = user), in the same group as the owner (g = group) or someone else (o = other).

To list the permissions of the files in a directory you give the command:

ls -l

Change permission

The command chmod changes the permission of a file. To add (+) write (w) permission to the group (g):

chmod g+w testfile

To remove the permission to read and write for the group (g) and others (o):

chmod go-rw testfile

Permissions can also be set using numbers and:

0 = no permissions
1 = execute
2 = write
4 = read

The numbers can be added to create a unique number. To set the permissions for users, the group and others type:

chmod 753 testfile

This sets the permission to:
users: read, write, execute (4+2+1)
group: read, execute (4+1)
others: write, execute (2+1)

The owner of the file can be set using chown and the group can be changed using chgrp

Common directories

/boot – Files needed for the system to boot
/etc – Configuration files
/sbin – System applications
/bin – User applications
/usr – Files belonging to the current user
/var – Variable sized files
/dev – Physical devices and terminals
/home – Home folder for every user