Skip to the content.

Chapter 7. Users/Groups and File Permissions Core Information [4 Hrs]

User:

Type of users

User related option file: /etc/login.defs

useradd: add new user -> create home dir default if CREATE_HOME=yes usermod: modify user -c : comment -e : expiredate -g : primary group -G : secondary group -k : skel directory -m : create home directory -M : do not create home directory -p : password -r : system account -s : shell eg. -s /usr/bin/zsh -u : user id

Lock User : usermod -L username Change Password : echo “Password” | passwd --stdin Lock Password: passwd -S

List of Users: getent passwd OR cat /etc/passwd Look user info : getent passwd OR cat /etc/passwd | grep "^" Look user password info : getent shadow -> ! shown if password not set Look user group : groups Look user password age: chage -l userdel: remove user -r : remove home directory too eg. sudo userdel -r binit

Groups

Creation and modification of Users and Group

Commands: useradd:

    useradd [options] username

passwd:

    passwd username

To change the password without using script:

    echo 'new_password' | passwd username --stdin

getent:

    getent passwd username
    getent shadow username

chage:

    chage -l username

usermod:

    usermod -g groupname username
    usermod -L mytest

groupadd:

    groupadd electronics -g 10 -U lisa
    groups lisa

File permissions

file permission looks like: drwxr-xr--

This can be separated into 4 parts: d rwx r-x r--.

First part represents the type of file. (discussed in chapter 5)

Second part represents the owner’s permission.

Third part represents the group’s permission.

Fourth part represents the other’s permission.

Permissions:

Symbolic notation

Example rwxr-xr– becomes 754

Useful commands: