IL-Module 5
IL-Module 5
Module 5
Topics to be covered:
Common administrative tasks
Identifying administrative files configuration and log files
Role of system administrator, managing user accounts-adding & deleting users,
changing permissions and ownerships, Creating and managing groups, modifying
group attributes, Temporary disabling of user’s accounts, creating and mounting file
system, checking and monitoring system performance
File security & Permissions, becoming super user using su.
Getting system information with uname, host name, disk partitions & sizes, users,
kernel
Installing and removing packages with rpm command.
5. Monitoring System Activities: Checking disc use and log files, Trying to free up disc
space, ensuring different services such as email, web services, network services are
working correctly.
6. Troubleshooting: figuring out malfunctions of services/programs/devices, rebooting
after a crash, answering users’ question.
7. Monitoring System Security: Set up security features such as Firewall, implement
security audits, run sniffers/scripts to check system, network and file system is secure.
8. Adding and removing hardware devices, configuring them.
9. Installing new software, upgrading system or the kernel, configuring servers like web
server, file server, mail server, etc.
10. Writing scripts to automate as many of the above tasks as possible
Configuration Files
In Linux and UNIX, system services are configured using various configuration files.
There are dozens of such files and may slightly different in different Linux
distributions. Configuration files can be global files, and local files.
Global /system-wide config files
Apply to all users
Usually located in /etc directory tree
Local/ User-specific config files
Applies to a specific user
Stored in the user’s home directory, usually hidden (AKA dot files).
The configuration files can be used for tasks related to Booting, Login/logout, File
system management, System administration, Networking etc.
System Administration
/etc/passwd : User authentication file contains the login data and is used during login
of a user.
8. Account expiration- The date (represented as the number of days since the January 1,
1970) on which the account will expire and the user will no longer able to log in.
9. Reserved for future
/etc/group : Configuration file for user groups. All the information related to groups
such as group name, group members, and group ID are stored in /etc/group file.
1. Group Name- This field stores a name of the group.
2. Group Password- This field specifies a password of the group and is generally left
blank. A value of x means password is stored in /etc/gshadow file for security reason.
A blank value means no password is assigned to this group.
3. Group ID(GID)- Every group is assigned a GID and this field is the place where GID
is stored.
4. Group Members- This field stores the usernames that belong to the group.
/etc/motd : Message of the day shown after a user logs in. Used if an administrator
wants to convey some message to all the users of a Linux server.
/etc/crontab : file specifies the system wide schedule of cron jobs that executes tasks
at specified intervals. These tasks are mostly used to automate system maintenance or
administration such as back up of data, updating the system with the latest security
patches, checking the disk space usage , sending emails, and so on.
/etc/cron.d directories contain scripts to be run periodically.
/etc/default: this is a special directory which holds the default configuration
information on some services, programs etc. For example, in /etc/default/useradd, you
can specify GROUP=500, so that your newly created users have 500 group id in default.
/etc/hosts : The file contains list of hosts with their IP addresses and corresponding host
names that can be contacted using the network.
/etc/hosts.allow: List of hosts allowed to access services on the Linux machine.
/etc/host.deny : List of hosts denied to access services on the Linux machine.
/etc/sysconfig/ : directory that contains the system's network configuration files
Sudo vs Su
On some Linux distributions like Ubuntu, the root user account is disabled by default
for security reasons. This means that no password is set for root and you cannot
use su to switch to root.
You can set the root password with following command: $ sudo passwd root
First, the command will prompt for your own password to confirm that you have sudo
privileges.
After you've entered your password, the passwd command will prompts you to enter a
new password for the root account (Twice).
Now you can log in to the root user using the su command and entering the root
password when prompted.
To delete a new user, you may use the command ‘userdel’ or ‘deluser’. The command
userdel is native binary compiled with the system. But, deluser is a script which
uses userdel in back-end. Administrators usually use deluser instead.
The command modifies the system account files, /etc/passwd , /etc/shadow , and
removes the entries of the user.
Syntax: userdel raju
Example: $ sudo userdel raju
Syntax: deluser raju
Example: $ sudo deluser raju
Changing Password
Change Your User Password
To change your own user’s account password, run the passwd command without any
arguments. You will be prompted to enter your current password. If the password is
correct, the command will ask you to enter and confirm the new password.
Example: $ passwd
Change Another User’s Password
To change the password of another user account, run the passwd command, followed
by the username. Only the root user and users with sudo access can change the
password of another user account.
Syntax: $ sudo passwd username
Example: $ sudo passwd raju
Options:
-d deletes the password of the user (makes it empty): $ sudo passwd -d raju
-e immediately expires an accounts password, and forces the user to change the
password at the next login $ sudo passwd -e raju
Modify Group
The groupmod command is used to modify an existing group in Linux. The /etc/group
file is modified by the command.
Syntax: groupmod [option] group
To change the name of the group from group_old to group_new, use the -n option
Example: $ sudo groupmod -n group_new group_old
To change the group id, use -g option. The following command changes the GID of
‘teaching’ group to 1002.
Example: $ sudo groupmod -g 1002 teaching
The value displayed by umask must be subtracted from the defaults of 777
(directories) and 666 (files) to determine your current defaults.
Remember that the umask specifies which permissions should not be granted
automatically to newly created files or directories.
Use the -S option to display the umask symbolically, in a form that shows which are
the permissions that are allowed.
Change Group
In Linux, each file is associated with an owner and a group. The chgrp command
changes the group ownership of given files.
Regular user can change the group of the file only if he owns the file and only to a
group of which he is a member. Administrative user can change the group ownership
of all files.
Syntax: chgrp [OPTIONS] GROUP FILE(s)
Example: To change the group of file ‘testfile’ to group ‘faculty’.
$ sudo chgrp faculty testfile
Example: To change the group of a link, use –h option
$ sudo chgrp -h faculty link_name
Example: To change the group of all files and directories under the given directory, use
–R option
$ sudo chgrp -R faculty dir1
To display the count of all matching entries, use the -c (--count) option.
Example: $ locate -c .bashrc
Process Management
A process in Linux is nothing but a program in execution. It’s a running instance of a
program. Any command that you execute starts a process. Every process is given a
unique process identification number (PID) by the kernel to identify and manage it.
There are two types of processes: foreground process and background process.
A foreground process is any command or program a user runs directly, interacts with
it, and waits for it to complete. Background processes run independently of a user.
Programs and commands run as foreground processes by default.
A process undergoes several states during its execution. There are several commands
to manage the states of a process particularly, the running state.
For example: ps, top, kill, nice, renice etc.
Example: $ top
You can use the up/down arrow keys to navigate up and down through the list. To quit
the display press q key. To kill a process, highlight the process with the up/down arrow
keys and press k key.
Click on Create New Disk and follow the instructions to create a virtual hard disk.
Click OK when the wizard completes to close the settings.
Now, start your virtual machine, logon to Ubuntu and open terminal window.
On the shell prompt, give either of the following commands to see the new hard disk:
/dev/sdb
$ sudo ls /dev/sd*
$ sudo fdisk -l
As we can see from the above output, the new hard drive has been assigned to the
device file /dev/sdb. Currently the drive has no partitions shown (because we have
yet to create any)
Enter m to see the command options; then enter p to print partition table.
As we can see from the above fdisk output, the disk currently has no partitions
because it is a previously unused disk. The next step is to create a new partition on
the disk, a task which is performed by entering n (for new partition) and p (for
primary partition).
We can create only one partition which will be named partition 1, so enter 1 for
partition number, press enter key to accept default sector. Then enter w (to write
and exit) save the partition and exit from the utility.
Now, type $ sudo ls /dev/sd* command to check the new partition created (i.e.
/dev/sdb1)
You can also use list block device command to check the partition:
$ lsblk
The next step is to create a Linux file system on the partition so that the operating
system can use it to store files and data. The easiest way to create a file system on a
partition is to use the mkfs.ext4 utility which takes as argument the partition device:
$ mkdir ~/diskB
$ mount –t ext4
Now, the new hard drive is attached with a new file system mounted to a mount point under
your home directory. But the file system is owned by root and you as a regular user can’t use
it. Give following command to check the ownership:
$ ls –la diskB
See the current directory (.) dot is owned by root. So, change the ownership to the regular
user (in this case acojha):
Now, you can create file in this directory ~/diskB without sudo command.
Persist the mount
File system mounted manually above will be unmounted when the virtual machine
shutdown.
To ensure that the drive is remounted automatically after a reboot, it must be added
to the /etc/fstab file.
It is also highly recommended that the UUID (Universally Unique Identifier) be used
in /etc/fstab to refer to the drive rather than just the device name (such
as, /dev/sdb1).
To find the UUID of the new drive, use the blkid utility:
$ sudo blkid