0% found this document useful (0 votes)
4 views

Lecture 6 User Management and System Administration in Linux

The document provides an introduction to user management and system administration in Linux, covering shell types, user and group management commands, and Linux permissions. It details commands for creating, modifying, and deleting users and groups, as well as managing services using init and systemd. Additionally, it explains Linux permission types and how to change ownership and permissions of files and directories.

Uploaded by

hamzaanwaar189
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 6 User Management and System Administration in Linux

The document provides an introduction to user management and system administration in Linux, covering shell types, user and group management commands, and Linux permissions. It details commands for creating, modifying, and deleting users and groups, as well as managing services using init and systemd. Additionally, it explains Linux permission types and how to change ownership and permissions of files and directories.

Uploaded by

hamzaanwaar189
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Introduction to User management

and system administration in Linux


What is shell (sh)
• Command language interpreter that executes commands
read from a command line string, the standard input, or a
specified file.
What is Bourne Shell
• (bsh)
Default interpreter for Version 7 Unix
• Unix like systems have /bin/sh
• Invokes the Bourne shell an interactive command
interpreter and command-programming language
What is Bash
• Bourne Again Shell (bash)
• Free and enhanced version of the Bourne shell (bsh)
distributed with Linux and GNU operating systems
Bash Version
• Default shell on Ubuntu is Bash (Bourne Again SHell)
⚬ $ bash --version
env
• command to print the list of environment variables or
run a utility in an altered environment without having
to modify existing environment
User management
• Creating User
Accounts
• Deleting User
Accounts
• Enabling User
Accounts
• Disabling User
Accounts
• Assigning Groups to
Users
• Assigning Shells to
User management
• Add New User
⚬ adduser
■ Add user to the system according to CLI options
and configuration information in
/etc/adduser.conf
■ friendlier than useradd
■ set home_dir, group, uid, gid, shell for new user
⚬ useradd
■ Low level utility for adding users
low level means closest to raw data, to the kernel interface etc.

Syntax: $ sudo adduser [options] user


User management
• Add New Group
⚬ addgroup
■ Add group to the system according to CLI
options and configuration information in
/etc/adduser.conf
■ friendlier than groupadd
⚬ groupadd
■ Low level utility for adding groups

Syntax: $ sudo addgroup [options] [--gid ID] group


$ sudo groupadd [options] group
User management
• Delete User
⚬ deluser
■ removes user from the system according to CLI
options and configuration information in
/etc/deluser.conf
⚬ userdel
■ Low level utility for deleting users

Syntax: $ sudo deluser [options] user


$ sudo userdel [options] user
User management
• Delete Group
⚬ delgroup
■ removes group from the system according to CLI
options and configuration information in
/etc/deluser.conf
⚬ groupdel
■ Low level utility for deleting groups

Syntax: $ sudo delgroup [options] [--only-if-empty] group


$ sudo groupdel [options] group
User management
• Modify User
⚬ usermod
■ modify a user account such as username,
password, home directory, default shell etc

Syntax: $ sudo usermod [options] user


User management
• Add user to a group
$ sudo usermod -a -G groupname username

• Change user's primary group


$ sudo usermod -g groupname username

• Remove user from a group


$ sudo gpasswd -d username groupname
User management
• chsh - change login shell for a user
$ sudo chsh [options] [LOGIN}

Available shells can be seen in /etc/shells file

• Change user's primary group


$ sudo usermod -g groupname username
see the groups in which the user belong using groups command

• Remove user from a group


$ sudo gpasswd -d username groupname
User management
• passwd command
⚬ Force Users to change passwords next time they
login
⚬ Lock a user's password (prevent it from being used)
⚬ Set minimum number of days before changing
password
⚬ Specify user when to change password
⚬ Set max number of days to use password without
changing
User management
• Disable User
$ sudo passwd -l user //lock

• Enable User
$ sudo passwd -u user //unlock

• Force to change password on next login


$ sudo passwd -e user //expire

• Max number of days a password remain valid


$ sudo passwd -x max_days user

• number of days to show a warning to change password


$ sudo passwd -w warn_days user
Switch User
• su username
• su [options] [-] [user [arguments...]]

• Can be used as a substitute user to run commands or


switch user.
Linux permissions
• User (u): Owner of the file or directory

• Group (g): Group of users added to have similar


permissions

• Others (o): anyone else other than owner and the


group
Linux permission Types
• Read (r): Read the contents of a file

• Write (w): Write and edit the contents of a file or a


directory

• Execute (x): Execute a program that is written in a file


or directory
Linux permission Types
• Read has value 4

• Write has value 2

• Execute has value 1


Linux permission String
• 10 characters in Linux Permission String (output of
ls -al)
⚬ First Character is the type of the file,
⚬ The first three characters of the remaining nine
characters are permissions for the user
⚬ The middle three characters are permissions for
group
⚬ Last three characters are permissions for others
Linux permission Matrix
Linux permission
Symbolic
• User => u
• Group => g
• Others => o
• All => a
• read => r
• write => w
• execute => x
• + => add
• - => remove
• = => set
Linux permission
Symbolic
chmod - Change Mode
• chmod command is used to change the permissions
of a file or directory
⚬ chmod [permissions] [filename]
⚬ chmod -R [permissions] [directoryname]
chown - Change
•Ownership
chown command is used to change the ownership of
a file or directory
⚬ chown [user:group] [filename]
⚬ chown -R [user:group] [directoryname]
chown - Change
Ownership
Init
• Stands for Initialization
• The first process started during the booting of the
computer system
• daemon process that continues running until the
system is shutdown
• A direct or indirect ancestor of all other processes
• automatically adopts all orphaned processes
• PID or Process ID is 1
• create processes from a script stored in /etc/inittab
⚬ configuration file used by initialization system
⚬ last step of kernel boot sequence
Init

• Init script initializes the service


• responsible for initializing the system
• init scripts are also called rc scripts (run command
scripts)
• Also used in UNIX
Init - services
• Start a service
⚬ service [service-name] start
• Stop a service
⚬ service [service-name] stop
• restart a service
⚬ service [service-name] restart
• reload a service
⚬ service [service-name] reload
• service status
⚬ service [service-name] status
Init - services
• Restart service if already running
⚬ service [service-name] condrestart
• enable service at startup
⚬ chkconfig [service-name] on
• disable service at startup
⚬ chkconfig [service-name] off
• check if service is enabled at startup
⚬ chkconfig [service-name]
• create new service file or modify configuration
⚬ chkconfig [service-name] add
Run-levels

• State of init
• group of processes are defined to start at the startup
of OS
• Mode of operation in the computer operating system
• Each run level has a certain number of services
started or stopped
Run-levels
• Seven Run levels exist ($ runlevel digit or $ init digit)
⚬ 0: Shuts down the system
⚬ 1: single-user mode
⚬ 2: multi-user mode without networking
⚬ 3: multi-user mode with networking (with CLI)
⚬ 4: user-definable
⚬ 5: multi-user mode with networking (with GUI)
⚬ 6: reboots the system to restart it
Run-levels
• By default, Linux based systems boot on runlevel 3 or
5
• user can modify preset runlevels
• create new ones according to the requirements
• Runlevel 2 and 4 are used for user defined runlevels
• runlevel 0 and 6 aur used for shutdown and reboot
the system
Systemd
• Systemd is the new init framework
• system and service manager for Linux operating
systems
• new distros are moving to systemd
• managing services with systemd
⚬ systemctl: control system and services
⚬ journalctl: manage journal, systemd's logging
system
⚬ hostnamectl: control hostname
⚬ localectl: configure locale and keyboard layout
⚬ timedatectl: set time and date
⚬ systemd-cgls: shows cgroup contents
Systemd - services
• see all services (running or not)
⚬ systemctl list-units --type service --all
• Start a service
⚬ systemctl start [service-name]
• Stop a service
⚬ systemctl stop [service-name]
• restart a service
⚬ systemctl restart [service-name]
• reload a service
⚬ systemctl reload [service-name]
Systemd - services
• see service status
⚬ systemctl status [service-name]
• Restart a service if already running
⚬ systemctl condrestart [service-name]
• Enable service at startup
⚬ systemctl enable [service-name]
• Disable service at startup
⚬ systemctl disable [service-name]
• check if service is enable at start up
⚬ systemctl is-enabled [service-name]
Systemd - services
• create new serivce file or modify configuration
⚬ systemctl daemon-reload
• systemctl halt
• systemctl poweroff
• systemctl reboot

You might also like