0% found this document useful (0 votes)
15 views26 pages

OSOS Linux Notes

Open-source operating systems allow users to view, modify, and share their source code, fostering community-led development and customization. Linux, the core of many open-source OS, is widely used across various platforms, including servers and smartphones, and offers features such as portability, multi-user capabilities, and robust security. While open-source OS can be cost-effective and flexible, they may require technical knowledge and lack dedicated technical support.

Uploaded by

brayndawaga
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views26 pages

OSOS Linux Notes

Open-source operating systems allow users to view, modify, and share their source code, fostering community-led development and customization. Linux, the core of many open-source OS, is widely used across various platforms, including servers and smartphones, and offers features such as portability, multi-user capabilities, and robust security. While open-source OS can be cost-effective and flexible, they may require technical knowledge and lack dedicated technical support.

Uploaded by

brayndawaga
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Open_Source Operating System

A software is said to be ‘open source’ when the owners or copyright holders


allow other users to see, use, and edit their product’s source code. Open-
source operating systems can be publicly accessed and edited. Users can
make changes to the available source code and produce applications as per
their requirements

On a closed-source OS like Windows, that code can only be altered by


Microsoft, and only viewed by few selected customers like big companies. In
contrast, the code underlying open-source operating systems is not only
freely available for anyone to view but also to modify, use and share, under
the terms of open-source licensees

Allowing anyone to inspect the source code in this way has many
advantages. Those with sufficient technical knowledge can customize the OS
and fix problems as they arise by digging into the source code.

It also allows the development of open-source operating systems to be


community-led, or at least influenced, with technical users suggesting
changes to an open-source operating system's codebase.

Linux Operating System

At the heart of most open-source operating systems today is the Linux


kernel. Linux provides the core of these operating systems, the kernel that
interacts with a computer's hardware.

Linux functionality is quite similar to UNIX since it was designed considering


UNIX compatibility.

As one of the most prominent and open-source software collaborations,


Linux is the leading operating system on 3 types of servers including File
Server, Web Server, and Database Server with extensive distributions
like Debian, openSUSE, Fedora Linux, Ubuntu, and hundreds of others

1
Components of Linux System

Linux Operating System has primarily three components

• Kernel − Kernel is the core part of Linux. It is responsible for all major
activities of this operating system. It consists of various modules and it
interacts directly with the underlying hardware. Kernel provides the
required abstraction to hide low level hardware details to system or
application programs.
• System Library − System libraries are special functions or programs
using which application programs or system utilities accesses Kernel's
features. These libraries implement most of the functionalities of the
operating system and do not require kernel module's code access
rights.
• System U t i l i t y − S y s t e m U t i l i t y p r o g r a m s a r e r e s p o n s i b l e t o
d o specialized, individual level tasks.

This kernel provides the core functionality any OS needs, controlling how
data is processed and parceled out into memory, how the system handles
files, how it interacts with devices plugged into the computer and other
fundamental tasks.

Operating system makers then build tools that plug into this Linux kernel to
create an operating system. These tools range from the windowing systems
that powers graphical desktops to the systems managing services running in
the background

2
Varieties of open-source operating systems

While Linux is at the heart of many operating systems, there is a huge


variety in the look and feel of Linux-based operating systems.

Some focus on simplicity and usability, such as Ubuntu, Linux Mint;

others on security, such as kali, tail; others on providing powerful tools for
technical experts, such as Debian and Gentoo. And while many have
similarities with the Windows desktop, others borrow design cues from
macOS, while others offer no graphical interface at all by default, just a bare
command line.

The most popular open-source operating system is Android, which is based


on a modified version of the Linux kernel. The issue is that what many
people think of as Android is not wholly open-source. At the core of the
Android OS is the Android Open-Source Project, which is open, as the name
suggests, but built around that are closed-source Google-branded apps.

There's also Chromium OS, the open-source operating system designed


around running web apps. While not widely distributed in on its own,
Chromium OS forms the basis of the Chrome OS that runs on Chromebooks,
which are particularly popular in the education market. Other than that,
Linux-based operating systems still only occupy between one to three
percent share of the desktop PC market.

When it comes to server operating systems, where Linux-based systems


such as Ubuntu, Red Hat Enterprise Linux and CentOS tend to dominate,
with Linux also a favorite on public cloud computing platforms, such as
Amazon Web Services, Google Cloud Platform, and Microsoft Azure.

Linux operating system is everywhere; smartphones, cars, supercomputers


and home appliances (refrigerators, televisions), home desktops to
enterprise servers. It also runs most of the Internet, all of the world’s top
500 supercomputers, and the world’s stock exchanges.

Besides being the platform of choice to run desktops, servers, and


embedded systems across the globe, Linux is one of the most reliable,
secure and worry-free operating systems available

3
Basic Features

Following are some of the important features of Linux Operating System.

• Portable − Portability means software can works on different types of


hardware in same way. Linux kernel and application programs supports
their installation on any kind of hardware platform.
• Open Source − Linux source code is freely available and it is
community-based development project. Multiple teams work in
collaboration to enhance the capability of Linux operating system and it
is continuously evolving.
• Multi-User − Linux is a multiuser system means multiple users can
access system resources like memory/ ram/ application programs at
same time.
• Multiprogramming − Linux is a multiprogramming system means
multiple applications can run at same time.
• Hierarchical File System − Linux provides a standard file structure in
which system files/ user files are arranged.

• Shell − Linux provides a special interpreter program which can be used


to execute commands of the operating system. It can be used to do
various types of operations, call application programs. etc.
• Security − Linux provides user security using authentication features
like password protection/ controlled access to specific files/ encryption
of data.

The open-source OS enables you to create a safe infrastructure for you to


work, run applications, manage files, process data, and anything that you
can think of.

4
Types of Open-Source Operating Systems
Broadly, open operating systems can be categorized into two types – Linux-
based and non-Linux based.
Linux Based Open-Source OS: Linux is an open-source operating system
for servers, computers, mobile devices, mainframes and embedded
solutions. It is supported by ARM, SPARC and every other computer
platform. Linux based open OS is capable of handling major tasks and
possibly all your computing needs. It offers a great piece-performance ratio,
along with being stable and highly customizable.
Non-Linux Based Open-Source OS: Despite the popularity of Linux-based
open-source operating systems, there are some great Unix based open-
source OS available in the market. These are based on BSD and ensure
built-in networking with file abstraction. Unix based multi-user computer OS
includes time-sharing configurations and multitasking features. Popular
examples are OpenBSD, PC-BSD, and NetBSD.

Pros and Cons of Open-Source Operating Systems


Cons
Flexible & Rapid: Open-source OS ensures that your IT team does not hold
itself back just because of the limited capability of the vendor. With open-
source OS, your IT team can create rather than just requesting and waiting
for the vendor. This will help you to stay ahead of your competitors.
Start Quickly: Getting started with an open-source OS is really speedy. You
can simply take the community versions and check how they suit your
business requirements. While moving forward, you can also grow your
business to a larger scale.
Cost-Effective: Along with offering the same value as compared to a
proprietary solution, open operating systems are inexpensive. However, they
offer equivalent or greater capabilities.
Robust Data Security: In the challenging internet environment, open-
source OS offers strong information security. One can even identify and fix
issues in decades-old open-source codes.
Attract Advanced Developers: Many developers know for a fact that
open-source code development is the future. The new-age talent prefers
open-source OS where they can create their own projects, enjoy flexibility,
and work freely.

5
Cons:
Requirement of Technical Knowledge: Many open operating systems are
not user-friendly, as using them requires certain technical knowledge. Many
are made for developers, so it becomes difficult to use for users who are not
tech-know-how. Also, if your IT team is reluctant or hesitant to adopt and
work on new technologies, open operating systems might become
challenging.
No Technical Support: Because many different people work on the same
open-source code, there is no technical team that you can go to for
assistance. Although you can connect to any third-party service providers
that might help you with any issues.
Problems with Compatibility: Running open-source OS requires the
installation of high-end specialist drivers that will add to your initial costs. So,
make sure to match your open source and hardware specifications.
Additional Associated Costs: There are a number of additional costs that
you might have to incur before its implementation. These additional costs
include hardware updates, training, support, implementation, etc.
Security Risk: Since it is an open operating system that is publicly available
and free to edit, you might have to deal with security risks. It might infect
your hardware or sensitive data by using an infected source code. However,
this risk can be minimized with commercial software that follows strict
security protocols.

Note about varieties of OSOS


GNU/Linux
Developed by Linus, it is one of the most popular examples of open-source
operating systems. Linux kernel operating system has evolved over the
years to become one of the most reliable computer ecosystems.
This open-source OS ensures that you don’t have to deal with any kind of
virus, malware, or ransomware. It offers zero entry cost, which means you
can install Linux on any computer without paying a shilling.
Linux Pricing: Linux is available for free.

6
• FreeBSD
This open operating system is an absolutely free UNIX open-source OS. It is
best used for intranet and internet server compatibility and networking.
Originated by the large community at University of California, this open-
source OS focuses on stability and speed. It can handle and manage large
loads of memory quite efficiently.
FreeBSD Pricing: FreeBSD is completely free to use.

• Android
The Android Open-Source Project is a great option for creating a production-
quality level OS mainly for consumer goods. This open-source Android OS
meets all the compatibility requirements to create a healthy and stable
Android ecosystem for its millions of users.
Android Pricing: Android offers free installation for its manufacturers and
customers.

• Chromium OS
This open-source OS is a Linux kernel operating system that uses Google
Chrome as its principal user interface. Chrome OS is compatible with all
Android as well as Linux applications.
Being a free open-source Android OS, Chromium OS offers Google cloud
print, improved security, virtual desktop access, cloud-based management,
an integrated multi-media player, and many more features. However, this
open operating system only supports its own hardware or Nexus devices.
Chromium Pricing: The open-source OS version of Chromium OS is
absolutely free.

• Ubuntu
A Linux-based open-source OS that is free to download, use, and share. It is
a feature-rich open-source operating system that provides office suite, web
browsers, instant messenger, media maps, etc. Ubuntu is one of the most
used examples of open-source operating systems and a great alternative to
Mac & Windows.
Ubuntu Pricing: Ubuntu offers a free plan and three paid plans – Essential,
Standard, and Advanced. This includes desktop, physical, virtual servers
with all other features.

7
• Linux Lite
Linux Lite is a great option for users who are not familiar with Linux based
OS and are looking for a light open-source OS. This open operating system
offers a light and simple user interface that can successfully run on low-end
hardware. The OS gets completely functional after installation and doesn’t
require the installation of any additional drivers.
Linux Lite Pricing: It costs some for an install or a Live DVD for 64 Bit.

• Fedora
A Linux-based open-source operating system that was created with the
purpose of providing high-end open-source OS for free. Fedora OS was
designed by the Fedora Project community and is currently supported by
Red Hat.
The developers at Fedora believe in creating upstream changes instead of
making fixes that are specific to Fedora. This makes the updates available
for all Linux distributions.
Fedora Pricing: Fedora is available for free to use, modify, or distribute.

• Linux Mint
It offers a perfect blend of power and modernity in a simple interface. Its
multimedia capabilities, stability, and appealing visual features make it
quite popular amongst both first-time users and experts. This Debian
architecture-based open-source OS is available for free to use.
Linux Mint: All the components of Linux Mint OS are completely free.

• Solus
Solus open-source operating system is the newest addition to Linux open-
source OS family. It offers OpenShot Video Editor, Budgie desktop
environment, VLC, Transmission, XChat Thunderbird, etc. Additionally, this
free open-source OS also offers pre-loaded Java and Flash plugins.
Solus Pricing: You can download Solus Budgie, Solus GNOME, Solus MATE,
and Solus Plasma for free from its website.

• React OS
React OS is considered to be a great alternative for Windows as it gives you
an option to run Windows apps. Being a developer-focused open-source OS.
it can be customized to meet your requirements.
React OS Pricing: React OS is completely free to use.

8
Why Adopt Open-Source Operating System?

The world IT leaders today recognize the potential of working on open-


source software. A Red Hat State of Enterprise Open-Source report, 2019
stated that only 1% enterprises ignore the value of open-source software.
This report was based on the interviews of about 950 IT leaders across the
world.

Linux is a core skill in the IT industry and is widely used in system administration,
cloud platforms and cybersecurity. Linux also forms the backbone of servers, cloud
infrastructure, and enterprise systems

File system
The Filesystem Hierarchy Standard is a hierarchy standard for Linux
organizing the file system structure. It defines the structure and content of
directories that contain files, along with their associate permissions and
ownership

The Linux file system is organized in a hierarchical tree-like structure, with


the root directory (/) at the top. All other directories and files are contained
within the root directory, which can be broken down into several
subdirectories. Some of the key directories and their purposes include:

/ (Root): The top-level directory of the file system.

/bin: Contains essential binary executables for the system.

/boot: Holds boot loader files, including the Linux kernel.

/dev: Contains device files, representing hardware devices.

/etc: Stores system configuration files. notable files include /etc/passwd,


which stores user account information

/home: Contains personal directories/files and settings for regular users.

/lib: Houses essential shared libraries and kernel modules.

/mnt: Used for mounting temporary filesystems.

9
/opt: Optional software packages.

/proc: Virtual filesystem providing process and system information.

/root: Home directory for the root user.

/sbin: System binaries, essential for system maintenance.

/tmp: Temporary files.

/usr: User binaries and read-only data.

/var: Variable data files, including logs and spool files.

Figure: the Linux File System Tree

10
General Linux commands

In Linux/Unix most operations are carried out by typing commands at a


command prompt, usually called a terminal or shell.

1. Listing files: ls. Ls -l. ls -a, ls -F

Ls /home/king lists files in the directory ‘/home/king’

2. Special characters

3. Files

cp file1 file2 makes a copy of file1 and calls it file2

mv file1 file2 moves (renames) file1 to file2

rm file1 removes (deletes) file1

rm -i file1 asks for confirmation that you want to delete file1

4. Directories

Pwd print the working directory

cd dirname change directory to the one called "dirname"

change to the parent directory of the current


cd ..
directory

cd ~ change to your home directory

mkdir dirname makes a new directory with name "dirname"

removes the directory with name "dirname".


rmdir dirname
The directory must be empty

11
rmdir - recursively removes directories and
r dirname subdirectories

5. Text files: can use vim, cat etc.

writes the whole of file "file1" to the terminal, also


cat file1
useful for concatenating files

more file1 displays the file "file1" a page at a time

a more versatile version of "more", but less


less file1
common

head -
show the first 30 lines
30 file1

tail -25 file1 show the last 25 lines

show the last few lines and keep updating as the


tail -f file1
file grows

wc file1 counts lines, words and characters in a file

6. Help

man utilityname manual pages for the command "utilityname"

7. Useful keypresses

interrupts whatever is currently running.


ctrl C
(It can get you out of trouble at embarrassing moments)

ctrl Z puts a foreground process into the background.

ctrl S suspends current terminal

ctrl Q resumes current terminal

12
8. Permissions and ownership

In Unix only the administrator (called "root") can modify everything.


Each file and directory is owned by one of the users, and (like users)
also belongs to a "group". As a user you can set whether your files can
be read, written or executed by just you, only members of your group,
or everyone. You can see the permissions of a file using ls -l. E.g.,

-rw-r----- 1 pi2026 abcs 3360 Jan 14 15:40 [Link]


drwxr-xr-x 2 pi2026 abcs 4096 Jan 15 23:56 Linux

The important part is the string of 10 characters at the start. The first
character says what type of thing this entry is, usually either "-" for a
normal file or "d" for a directory. You can see in the example that
"[Link]" is a file, and "Linux" is a directory.

The next nine characters are actually grouped as three sets of three.
The first set of three refers to the permissions the owner, in this case
"pi2026" (me). The "r" means I can read the file, the "w" means I can
write to the file, and the "-" means that I cannot execute it. If I could
execute it, it would have an "x" in the third permission. For directories
"execute permission" has a different meaning -- it means I can list its
contents.

The next set of three refers to users who are not the owner (pi2026 in
this case) but are in the same group as the owner (abcs in the
example above). In the example above users in the group abcs can
read the file "[Link]" but not write to it.

The final three characters refer to anyone who is neither the owner,
nor in the same group as the file.

Chmod changes file and directory permissions

chmod change permissions of "file1" so user ("u") gains


u+r file1 ("+") read permission ("r").

chgrp group1
change "file1" to belong to group "group1"
file1

13
In general, the permissions use the following format:

u User

g Group

o Others

a all (equivalent to ugo)

+ Gain

- Lose

r read permission

w write permission

x execute permission

Each file or directory in Linux has three sets of permissions:


Owner: The user who owns the file.
Group: The group of users who have permissions on the file.
Others: All other users on the system.
Eg: chown user:group [Link], change the ownership of [Link] to user and group.

These can be combined, so for example to grant read and write permission to
the user who owns a file and anyone in the same group as the file you could
use chmod ug+rw.

9. Using printers

lp -P printername file1 prints file1 to printer "printername"

lpq -P printername enquiry, print queue

lprm -P printername removes print job "jobnumber" from


jobnumber print queue

10. Calculator bc -l
14
11. Processes

ps list my processes (programs) that are running, along with


their process ID (PID)

kill pid kill (stop) my process with the given PID

show the top few processes sorted according to CPU


usage
top
Once top is running, type M to sort by memory usage
instead, and q to quit

12. Searching for things

sort files sort the specified files

grep pattern files search files for particular patterns

find dirname - search directory "dirname" and


name file1 subdirectories for files called "file1"

13. Previous Commands

You can use the up and down arrows on the keyboard to scroll through
previous commands. Alternatively:

lists your last 15 (variable) commands and


history 15
numbers them

!! repeats your last unix command

!23 repeats the command numbered 23

repeats the last command beginning with e.g.


!f90
"f90"

!!addtext appends "addtext" to previous command line

substitutes "string2" for "string1" in previous


^string1^string2
command

15
14. Redirection

Many commands take their input from the keyboard and write their
output to the terminal window, but this isn't always what you want.
You can redirect the input and output of commands.

redirects the output of "command" to


command > file1 "file1"
instead of to standard output (screen)

appends the output of "command" to


command >> file1 "file1"
instead of to standard output (screen)

command < file1 takes input for "command" from file1

pipe standard output of command1 to


command1 | command2
standard input of command2

15. Remote access

login securely as user "user1" into


ssh user1@machine1
machine "machine1".

copy file "file1" to the home directory of


scp file1
user "user1" on
user1@machine1:
machine "machine1". Note the colon!

interactive secure ftp (file transfer


sftp machine1
program)

16. Compressing files

compress file "file1". The compressed file will be


gzip file1
called "[Link]"

uncompress file "[Link]". The uncompressed file


gunzip [Link]
will be called "file1"

16
User Management Commands for System Admins:

User management commands in Linux are tools that allow administrators to


create, modify, delete, and manage user accounts and groups by assigning
user to groups, manage passwords, enforce security policies.
These commands play a significant role in user authentication, access control,
and overall system security. Mastering these commands helps administrators
maintain secure and organized user environments in Linux, ensuring proper
access control and efficient system management.

Linux OS allows multi-user access options. Different users can access the
same Linux OS for working simultaneously. A user account allows multiple
people to access directories, terminals, the Internet, etc. There are three
types of user accounts:
• User Account: This account is for general use with limited
permissions.
• System Account: This account is used for operating specific
programs such as MySQL, mail, etc.
• Root Account: This account is for administrators. It has unlimited
access to change the system

Keep in mind that you need to be root or a sudo user in order to


use this command.
Add a new user in Linux with useradd command
You can use the useradd command without any options like this:
useradd new_username
It will create the user account but:
• the user’s home directory won’t be created
• the password has to be set separately
• the default shell for the user will be sh

passwd new_username
passwd Command Examples
The passwd command in Linux allows you to change user password, lock
accounts, expire passwords and more.

17
1. Change your own password
To change the current user’s password i.e. your own account password,
just enter the passwd command without any options.
passwd

(current) Linux password:


Enter new Linux password:
Retype new Linux password:
passwd: password updated successfully
If you enter your current password as the new password, the system will
throw an error message saying that the password is unchanged and
prompt you again for a new password.

2. Create root password


Many Linux distributions come without a root password set. The only way
to access root account is through sudo or su commands. This is because
a default password like ‘root’ would make a system vulnerable to
attackers.
You must be a sudo user to create root password:
sudo passwd root
Here’s the output:
you@linux:~$ sudo passwd root
[sudo] password for you:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
This is one of many reasons why it is critical to properly configure user
access. You wouldn’t want all users to be able to change your root
password!

3. Change other user’s password


You can change user password in Linux using passwd command as root
or with sudo.
sudo passwd user_name
You won’t be asked for the old password obviously. You are resetting the
password after all and as the admin, you should be able to do that.
root@linux:/home/you# passwd you
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

18
1. useradd— Adding New Users
This command is used to create a new user on the system. When a new user
is created, a home directory is typically created for them, and default settings
from the system’s skeleton directory are applied.
Basic Syntax:
useradd [OPTIONS] USERNAME

Common Options:
• -m: Creates a home directory for the new user.
• -s /bin/bash: Sets the default shell for the user (e.g., Bash).
• -d /home/customdir: Specifies a custom home directory for the user.
• -g GROUPNAME: Assigns the user to a primary group.
• -G GROUP1,GROUP2: Assigns the user to multiple supplementary
groups.
Example:
useradd -m -s /bin/bash -g users -G java,developers George

• This creates a user George with a home directory, Bash shell, primary
group users, and supplementary groups java and developers.

2. usermod — Modifying Existing Users


This command is used to modify the settings of an existing user. It allows
you to change various user attributes such as their home directory, group
membership, shell, etc.
Basic Syntax:
usermod [OPTIONS] USERNAME
Common Options:
• -l NEWNAME: Changes the username of an existing user.
• -g GROUP: Changes the primary group of the user.
• -G GROUP1,GROUP2: Adds the user to supplementary groups.
• -d /new/home/dir: Changes the user’s home directory.
• -s /bin/zsh: Changes the default shell to Zsh.
Example:
usermod -l George_king -d /home/George_king -m George
• This modifies the user George by renaming them to George_king and
moving their home directory to /home/George_king.

19
3. userdel — Deleting Users
The userdel command is used to remove a user from the system. By default,
the user’s home directory and files are not deleted unless specified.
Basic Syntax:
userdel [OPTIONS] USERNAME
Common Options:
• -r: Removes the user’s home directory and mail spool along with the
user account.
Example:
userdel -r ALLY

• This removes the user ALLY along with their home directory and mail
files.

4. passwd — Managing User Passwords


The passwd command is used to manage user passwords. It can be used to
change the password of a user, force a password change, and manage
password expiry settings.
Basic Syntax:
passwd [OPTIONS] USERNAME

• This changes the password for the user ALLY.

5. groupadd — Adding Groups


The groupadd command creates a new group on the system. Groups are used
to organize users and control access to files and resources.
Basic Syntax:
groupadd [OPTIONS] GROUPNAME
Common Options:
• -g GID: Specifies the group ID for the new group.
Example:
groupadd developers
• This creates a new group called developers.

20
6. groupdel — Deleting Groups
The groupdel command deletes a group from the system.
Basic Syntax:
groupdel GROUPNAME
Example:

groupdel developers

• This removes the developers group from the system.

7. groupmod — Modifying Groups


The groupmod command allows you to modify an existing group, such as
changing its name or group ID.
Basic Syntax:
groupmod [OPTIONS] GROUPNAME
Common Options:
• -g GID: Changes the group ID.
• -n NEWNAME: Renames the group.
Example:
groupmod -n engineers developers
• This renames the group developers to engineers.

8. gpasswd — Managing Group Memberships


The gpasswd command is used to administer /etc/group and /etc/gshadow,
including managing group memberships.
Basic Syntax:
gpasswd [OPTIONS] GROUPNAME

Common Options:
• -a USER: Adds a user to a group.
• -d USER: Removes a user from a group.
Example:
gpasswd -a john developers

• This adds the user john to the developers group.

21
9. chage — Managing Password Expiration
The chage command is used to set or view a user’s password expiration
settings. It helps in enforcing password policies like how long a user can
keep the same password.
Basic Syntax:
chage [OPTIONS] USERNAME

Common Options:
• -l: Lists a user’s password aging information.
• -M DAYS: Sets the maximum number of days a password remains
valid.
• -m DAYS: Sets the minimum number of days between password
changes.
• -E DATE: Sets the account expiration date.
Example:
chage -l john

• This displays the password expiration information for the user john.

10. id — Displaying User and Group IDs


The id command shows the user and group IDs of a specified user or the
current user.
Basic Syntax:
id john

• This displays the user ID (UID), group ID (GID), and supplementary


group information for the user john.

NOTICE:
Practice on these commands to make it comfortable for you and
gain/discover important skills in Linux operating system management. Use
the practical class sessions for this exercise.

22
Advanced User Management Commands
With addition to above, here are some advanced commands for Linux user
management, showing how o n e can use various options and combine
commands for more complex user and group management tasks: this allows
precise control over user accounts, including managing groups, passwords,
expiration dates, and user permissions.
These commands can be combined with shell scripting for automation, helping
system administrators efficiently handle large-scale user management tasks on
Linux systems. Understanding and mastering these advanced commands
ensures a secure and organized environment for managing users and groups
in Linux.

1. Creating a New User with Custom Settings


Example:
useradd -m -s /bin/zsh -d /home/student -g developers -G sudo,admin -c
"Student" student
• Description: This command creates a new user student with:
o A home directory /home/student
o A default shell of Zsh
o A primary group developers
o Supplementary groups sudo and admin
o A comment field (real name) “Student”

2. Assigning an Expiry Date to a User Account


Example:
Useradd -e 2026-01-31 -m student_expire
• Description: This command creates a user student_expire with a home
directory and sets an account expiration date of January 31, 2026. After
this date, the account will be disabled.
3. Forcing a Password Change on First Login
Example:
passwd -e student
Description: This command forces the user student to change their password
on their next login by expiring the current password.

23
4. Changing Multiple User Attributes Simultaneously
Example:
Usermod -d /home/new_home -l new_name -s /bin/bash old_name

• Description: This command modifies the user old_name by:


o Changing the username to new_name
o Changing the home directory to /home/new_home
o Changing the default shell to Bash

5. Setting Password Expiration Policy


Example:
change -M 60 -m 7 -W 7 user1

• Description: This command sets a password policy for the user user1:
o Maximum age: Password must be changed every 60 days
o Minimum age: Password must be kept for at least 7 days before
changing
o Warning: User is warned 7 days before the password expires

6. Locking and Unlocking User Accounts


• Locking:
passwd -l user1

• Description: Locks the account user1 by disabling the password.


Unlocking:
Passwd -u user1
o Description: Unlocks the account user1 and re-enables the
password.

7. Creating a New Group and Adding Multiple Users


Example:
groupadd dev_team && gpasswd -a user1 dev_team.&& gpasswd -a user2
dev_team
• Description: This creates a new group dev_team and adds
both user1 and user2 to the group.

24
8. Adding a User to Multiple Groups
Example:
Usermod -aG programmers,developers,sudo user1

• Description: This command adds user1 to the


groups programmers, developers, and sudo without removing them
from any existing groups.

9. Removing a User from a Specific Group


Example:
Gpasswd -d user1 develpers

• Description: This command removes the user user1 from the


group developers.

10. Removing a User but Keeping Their Home Directory


Example:
userdel user1

• Description: This deletes the user user1 from the system but keeps
their home directory intact. If you want to remove the home directory
as well, use the -r flag.

11. Listing All Groups and Their Members


Example:
getent group

• Description: This command lists all the groups on the system and
their members.

25
12. Deleting a User and Transferring Ownership of Files
Example:
Find /home/user1 exec chown new_owner: new_group {} \; && userdel -r
user1

• Description: This command first changes the ownership of all files


under /home/user1 to new_owner:new_group and then deletes the
user user1 along with their home directory.

13. Batch Creating Users from a Text File


Example:
while IFS=, read -r username password; do
useradd -m $username && echo "$username:$password" | chpasswd
done < [Link]

• Description: This script reads a CSV file ([Link]) with usernames


and passwords, then creates each user and sets their password.

14. Checking User’s Last Login


Example:
Last -u user1
• Description: This command checks the last login time for the
user user1.

15. Setting Account Expiry After a Certain Inactivity Period


Example:
chage -I 30 user1

• Description: This command locks the user account user1 after 30 days
of inactivity.

26

You might also like