Module - 4
Module - 4
System Administration
System Administration
• Linux system is intended for multi-user &
multitasking.
• Who is System Administrator?
• A System Administrator is a person who is
responsible for the upkeep, configuration and
reliable operation of computer systems;
especially multi-user computers, such as
servers.
Using the root user account
Every Linux system starts out with at least one
administrative user account (the root user) and possibly
one or more regular user accounts. In most cases, you
log in as a regular user and become the root user to do
an administrative task.
The root user has complete control of the operation of
your Linux system. That user can open any file or run any
program. The root user also installs software packages
Becoming root from the shell (su command)
in the past, the root user had to configure network interfaces and
start and stop those interfaces. Now, many Linux desktops allow
regular users to start and stop network interfaces from their
desktop using Network Manager. This is particularly true for
wireless network interfaces, which can come and go by location, as
you move your Linux laptop or handheld device around.
Common Administration Tasks
5. Servers:
configuring web servers, file servers, domain name servers, main
servers, and dozens of other servers requires root privilege, as does
starting and stopping those services. Content, such as web pages, can
be added to servers by no-root users if you configure your system to
allow that. Services are often run as special administrative user
accounts, such as apache and rpc. So if someone cracks a service,
they can’t get root privilege to other services or system resources.
Common Administration Tasks
6. Security Features:
Setting up security features, such as firewalls and user access
lists, is usually done with root privilege. It’s also up to the root
user to monitor how the services are being used and make sure
that server resources are not exhausted or abused.
Identifying Administrative files
Configuration and log files.
Administrative Commands
•Only the root user is intended to use many administrative commands. When you log in
as root (or use su - from the shell to become root), your $PATH variable is set to
include some directories that contain commands for the root user. In the past, these
have included the following:
•/sbin—Contained commands needed to boot your system, including commands for
checking filesystems (fsck) and turn on swap devices (swapon).
• Some administrative commands are contained in regular user directories (such as /
bin and /usr/bin). This is especially true of commands that have some options
available to everyone. An example is the /bin/mount command, which anyone can use
to list mounted file systems, but only root can use to mount file systems.
Administrative configuration files
• Configuration files are another mainstay of Linux administration. Almost
everything you set up for your particular computer—user accounts, network
addresses, or GUI preferences—is stored in plaintext files. This has some
advantages and some disadvantages.
• The advantage of plain text files is that it’s easy to read and change them. Any
text editor will do.
• The disadvantage is that you need to learn the specific structure rules for each
configuration fi le. A comma or a quote in the wrong place can sometimes
cause an entire interface to fail.
Configuration Files
File Name What the file configures
/etc This directory contains most of the basic Linux system configuration files.
/etc/cron* Directories in this set contain files that define how the crone utility runs
applications on a daily (cron.daily), hourly (cron.hourly), monthly (cron.monthly), or
weekly (cron.weekly) schedule.
/etc/init.d Contains the permanent copies of System V-style run-level scripts. These scripts
are often linked from the /etc/rc?.d directories to have each service associated
with a script started or stopped for the particular run level. The ? is replaced by the
run-level number (0 through 6). Although System V init scripts are still supported,
most services are now managed by the systemd facility.
Log Files
•One of the things that Linux does well is keep track of itself. This is a good thing,
when you consider how much is going on in a complex operating system.
•Checking illegal access .
•In any of those cases, you want to be able to refer to messages coming from the
kernel and services running on the system.
• For Linux systems that don’t use the systemd facility, the main utility for logging
error and debugging messages is the rsyslogd daemon. Although you can still use
rsyslogd with systemd systems, systemd has its own method of gathering and
displaying messages called the systemd journal (journalctl command).
Role of System Administrator
•The role of a Linux system administrator is to
keep Linux-based computer systems running
efficiently
•A system administrator works as part of the
Information Systems (IS) or Information
Technology (IT) department of an organization.
•Help users solve problems
Role of System Administrator
• Train users
• Plan systems
Managing user accounts-adding and
deleting users
Creating user accounts
• You can add user accounts to most Linux systems in several
ways.
• In GNOME 3, go the the Activities screen, type Users, and press
Enter.
• In GNOME 2, from the Applications menu, select System Tools ➪
Settings. Then select the Users icon. Select the Unlock button,
and enter the root password. Then select the plus (+) to open a
window for adding a user account, as shown in Figure
Add user accounts from the user window
Modify existing user accounts
• The Software window lets you modify a small set of information
about a regular user after it has been created. To modify user
information later, select the user account you want to change, click
the Unlock button, and enter the root password. At this point, you
can change the account type (Standard or Administrator), change
the user’s password, or allow the user account to log in
automatically (without a password). This screen is shown in Figure
Modify existing user accounts from the
Users window
• The Users window was designed to simplify the process of
creating and modifying user accounts.
Adding users with useradd
• The most straightforward method for creating a new user from the shell is the useradd
command. After opening a Terminal window with root permission, you simply invoke
useradd at the command prompt, with details of the new account as parameters.
• The only required parameter is the login name of the user, but you probably want to
include some additional information ahead of it. Each item of account information is
preceded by a single-letter option code with a dash in front of it. The options available
with useradd include the following:
• -c "comment here"—Provide a description of the new user account. Typically, this is the
person’s full name. Replace comment with the name of the user account (-c Jake). Use
quotes to enter multiple words (for example, -c "Jake Jackson").
Adding users with useradd
• -d home_dir—Set the home directory to use for the account. The default is to
name it the same as the login name and to place it in /home. Replace
home_dir with the directory name to use (for example, -d /mnt/homes/jake).
• -D—Rather than create a new account, save the supplied information as the
new default settings for any new accounts that are created.
• -e expire_date—Assign the expiration date for the account in YYYY-MM-DD
for-mat. Replace expire_date with a date you want to use. (For example, to
expire an account on May 5, 2017, use -e 2017-05-05.)
• -f -1—Set the number of days after a password expires until the account is
per-manently disabled. The default, -1, disables the option. Setting this to 0
disables the account immediately after the password has expired. Replace -1
(that’s minus one) with the number to use.
Adding users with useradd
• -g group—Set the primary group (it must already exist in the /etc/group fi le) the new user will be in.
Replace group with the group name (for example, -g wheel). Without this option, a new group is
created that is the same as the user name and is used as that user’s primary group.
• -G grouplist—Add the new user to the supplied comma-separated list of supplementary groups (for
example, -G wheel,sales,tech,lunch). (If you use -G later with usermod, be sure to use -aG and not
just -G. If you don’t, existing supplementary groups are removed and the groups you provide here
are the only ones assigned.)
• Let’s create an account for a new user. The user’s full name is Sara Green, and her login name is sara.
To begin, become root user and type the following command:
• useradd -c "Sara Green" sara
• Next, set the initial password for sara using the passwd command. You’re prompted to type the
password twice:
• passwd sara
• Changing password for user sara.
• New password: **********
• Retype new password: **********
Modifying users with usermod
• The usermod command provides a simple and straightforward method
for changing account parameters. Many of the options available with it
mirror those found in useradd. The options that can be used with this
command include the following:
• -c username—Change the description associated with the user account.
Replace username with the name of the user account (-c jake). Use
quotes to enter multiple words (for example, -c "Jake Jackson").
• -l login_name—Change the login name of the account.
• -L—Lock the account by putting an exclamation point at the beginning of
the encrypted password in /etc/shadow. This locks the account, while
still allowing you to leave the password intact (the -U option unlocks it).
Deleting users with userdel
• Just as usermod is used to modify user settings and useradd is used
to create users, userdel is used to remove users. The following
command removes the user chris:
• userdel -r chris
• Here, the user chris is removed from the /etc/password file. The –r
option removes the user’s home directory as well. If you choose not
to use –r, as follows, the home directory for chris is not removed:
• userdel chris
• Before you delete the user, you may want to run a find command to
find all files that would be left behind by the user. After you delete the
user, you could search on user ID to find files left behind. Here are
two find commands to do those things:
• find / -user chris -ls
• find / -uid 504 -ls
Changing Permissions and
Ownerships
File Access Permissions
• Permissions associated with files and directories in Linux were designed to
keep users from accessing other users’ private files and to protect important
system files.
• The nine bits assigned to each file for permissions define the access that
you and others have to your fi le. Permission bits for a regular file appear as
-rwxrwxrwx. Those bits are used to define who can read, write, or execute the
file.
• Of the nine-bit permissions, the first three bits apply to the owner’s
permission, the next three apply to the group assigned to the fi le, and the
last three apply to all others. The r stands for read, the w stands for write,
and the x stands for execute permissions. If a - appears instead of the letter,
it means that permission is turned off for that associated read, write, or
execute bit.
Access Permissions
Access type Denoted by Action permitted on a Action permitted on a
file directory
read r Display, Copy and List contents of a
compile file directory
write w Edit, rename and move Create new files and
the file to another subdirectories within the
location directory
execute x Execute file with the Move to the specified
read permission directory using the cd
command
File Access Permissions
• you can see the permission for any file or directory by typing the ls -ld
command. The named file or directory appears as those shown in this
example:
• $ ls –ld ch3 test
• -rw-rw-r– 1 joe sales 4983 Jan 18 22:13 ch3
• drwxr-xr-x 2 joe sales 1024 Jan 24 13:47 test
• The first line shows that the ch3 file has read and write permission for the
owner and the group. All other users have read permission, which means
they can view the file but cannot change its contents or remove it. The
second line shows the test directory (indicated by the letter d before the
permission bits). The owner has read, write, and execute permissions
while the group and other users have only read and execute permissions.
Changing permissions with chmod (numbers)
• If you own a fi le, you can use the chmod command to change the permission
on it.
• The following table explains the number that denotes each type of permission.
Number permission
4 Read
2 write
1 execute
• Examples:
• The following chmod command results in this permission: rwxrwxrwx
• # chmod 777 file
• The following chmod command results in this permission: ---------
• # chmod 000 file
Changing permissions with chmod (letters)
•In the symbolic mode we can use symbols to specify the permissions and types of users.
Symbol Meaning
u Owner of the file or directory
g Members of the same group
o All other users
a All users
•Examples:
•The following chmod command results in this permission: r-xr-xr-x
•$ chmod a-w file
•The plus sign is used with chmod to turn permissions on.
•The following chmod command results in this permission: rw-------
•$ chmod u+rw files
Setting default file permission with umask
• When we create a file the umask value and the mode value
determine the initial file permissions.
• The mode value indicates that all the users have read and write
permissions for a file. By default the mode value is 666 for files
and 777 for directories and executable files. To derive file
access permissions, the value of umask is subtracted from the
mode value.
• By default the umask value is given as 002 for user and 022 for
root user which means that each file that a user creates has the
permission 666 -002 =664 (rw-rw-r--)
Values & output of the umask command
on files
066 -rw------ Assigns read and write permissions to user and no
access for group or others
026 -rw-r----- Assigns read and write permissions to a user , read
permissions to a group and no access to other
users.
006 -rw-rw---- Assigns read and write permissions to a user and
group but no access to other users.
022 -rw-r—r-- Assigns read and write permissions to a user , read
permissions to a group and read permission to
others
Changing file ownership
• As a regular user, you cannot change ownership of files or directories to have them
belong to another user. You can change ownership as the root user. For example,
suppose you created a file called memo.txt, while you were root user, in the user joe’s
home directory. Here’s how you could change it to be owned by joe:
• chown joe /home/joe/memo.txt
• ls -l /home/joe/memo.txt
• -rw-r--r--. 1 joe root 0 Dec 19 11:23 /home/joe/memo.txt
• Notice that the chown command changed the user to joe but left the group as root. To
change both user and group to joe, you could type the following instead:
• chown joe:joe /home/joe/memo.txt
• ls -l /home/joe/memo.txt
• -rw-r--r--. 1 joe joe 0 Dec 19 11:23 /home/joe/memo.txt
The chown command can be use recursively as well. Using the recursive option (-R) is
helpful if you need to change a whole directory structure to ownership by a particular user.
# chown -R joe:joe /media/myusb
Creating and Managing groups
Creating Groups with groupadd
• groups are created automatically when a user account is created.
• Group ID numbers from 0 through 999 are assigned to special administrative
groups. For example, the root group is associated with GID 0. Linux systems
reserve GIDs between 0 to 500 for administrative groups.
• examples of creating a group account with the groupadd command:
• groupadd kings
• groupadd -g 1325 jokers
• In the examples just shown, the group named kings is created with the next
available group ID. After that, the group jokers is created using the 1325 group
ID. Some administrators like using an undefined group number under 1000 so
the group they create doesn’t intrude on the group designations above 1000.
Modifying Group Attributes
• To change a group later, use the groupmod command. For
example:
• groupmod -g 330 jokers
• groupmod -n jacks jokers
• In the first example, the group ID for jokers is changed to 330. In
the second, the name jokers is changed to jacks. If you wanted to
then assign any of the groups as supplementary groups to a user,
you can use the usermod command.
Deleting Groups
After a group has been added it can be deleted with the groupdel
command.
Deleting a Group
# groupdel folks
The groupdel command will remove all references of the folks
group from the /etc/group file.
# grep -c folks /etc/group
0
Temporary disabling of user accounts
• It is sometimes necessary to temporarily disable an account, without
removing it. For example, the user might not have paid his fees, or the
system administrator may suspect that a cracker has got the password of
that account.
• The best way to disable an account is to change its shell into a special
program that just prints a message. This way, whoever tries to log into the
account, will fail, and will know why. The message can tell the user to
contact the system administrator so that any problems may be dealt with.
Temporary disabling of user accounts
• It would also be possible to change the username or password to
something else, but then the user won't know what is going on.
Confused users mean more work.
• A simple way to create the special programs is to write `tail scripts':
• #!/usr/bin/tail +2
This account has been closed due to a security breach.
Please call 555-1234 and wait for the men in black to arrive.
• The first two characters(#!) tells the kernel that the rest of the line is a command
that needs to be run to interpret this file. The tail command in this case outputs
everything except the first line to the standard output.
• Tail scripts should be kept in a separate directory, so that their names
don't interfere with normal user commands.
Creating and Mounting File System
• Creating a file system writes information to the device and creates
order of the empty space.
• Disk drive is split into consistently sized segments called blocks.
• Linux supports a number of file system types, some of which are
described as follows:
Filesystem Description
-a, --alias Display the alias name of the host (if used). This option is deprecated and should not be used anymore.
-A, --all-fqdns Displays every FQDN of the machine. This option enumerates all configured network addresses on all
configured network interfaces, and translates them to DNS domain names. Addresses that cannot be
translated (i.e. because they do not have an appropriate reverse DNS entry) are skipped. Note that different
addresses may resolve to the same name, therefore the output may contain duplicate entries. Do not make
any assumptions about the order of the output.
-b, --boot Always set a hostname; this allows the file specified by -F to be non-existant or empty, in which case the
default hostname localhost will be used if none is yet set.
-d, --domain Display the name of the DNS domain. Don't use the command domainname to get the DNS domain name
because it will show the NIS domain name and not the DNS domain name. Use dnsdomainname instead.
-f, --fqdn, --long Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a short host name and the DNS domain
name.
-F, --file file name Read the host name from the specified file. Comments (lines starting with a `#') are ignored.
-i, --ip-address Display the network address(es) of the host name. Note that this works only if the host name can be resolved.
Avoid using this option if at all possible; use hostname --all-ip-addresses instead.
-I, --all-ip-addressesDisplay all network addresses of the host. This option enumerates all configured addresses on all network
interfaces. The loopback interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option
Disk Partitions and sizes
• Linux provides several tools for managing your hard disk partitions. You need to
know how to partition your disk if you want to add a disk to your system or change
your existing disk configuration.
• PC architecture computers have traditionally used Master Boot Record (MBR)
partition tables to store information about the sizes and layouts of the hard disk
partitions. There are many tools for managing MBR partitions that are quite stable
and well known. In the past few years, however, a new standard called Global Unique
Identifiers (GUID) partition tables began being used on systems as part of the UEFI
(unified extensible Firmware Interface-first program that runs when a computer is
turned on) computer architecture to replace the older BIOS method of booting the
system.
Disk partitions
Viewing disk partitions
To view disk partitions, use the fdisk command with the -l option. The
following is an example of partitioning on a 160GB fixed hard drive on
a Red Hat Enterprise Linux 7 system:
•fdisk -l /dev/sda
Disk /dev/sda: 160.0 GB, 160000000000 bytes, 312500000 sectors Units =
sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008870c
Device Boot Start End Blocks Id System
• # rpm -e emacs