Lab Manual FOR Unix Operating System: Ms. A.K. Ingale
Lab Manual FOR Unix Operating System: Ms. A.K. Ingale
FOR
Prepared By
Ms. A.K. Ingale
Academic Year
2020-21
EXPERIMENT NO 1
Title: Introduction to Linux
Aim: Study the basic of linux OS
Theory:
About Linux
The Terminal
For most of the time you access a cloud server, you’ll be doing it through a terminal shell.
The shell allows you to execute commands on the droplet.
All administrative tasks can be accomplished through the terminal. This includes file
manipulation, package installation, and user management.
The terminal is interactive. You specify commands to run. The terminal outputs the results of
those commands. Executing any command is done by typing it and pressing Enter.
Navigation
Linux filesystems are based on a directory tree. This means that you can create directories (or
“folders”) inside other directories, and files can exist in any directory.
pwd
This stands for “print working directory”, and will print the path to your current directory.
The output can look similar to this:
/home/foo
This means that your current active directory is foo, which is inside home, which lives in the
root directory, /.
To see other files and directories that exist in your current working directory:
ls
This will give you a list of names of files and directories. To navigate into a directory, use its
name:
cd <name of directory>
This will change your new current working directory to the directory you specified. You can
see this with pwd.
Additionally, you can specify .. to change to the directory one level up in your path. To get
back to your original directory:
cd ..
We can also create new directories in our current working directory. For example, to create a
new directory called bar:
mkdir bar
Then we can <pre>cd</pre> into bar if we want. We can also delete bar if we no longer find
it useful:
rm -d bar
<pre>rm -d</pre> will only delete empty directories.
Problem Statements:
Obtain the following results
2. Find out the users who are currently logged in and find the particular user too.
(v) Current Date Day Abbreviation , Month Abbreviation along with year
4. Display the time in 12-Hour and 24 Hour Notations.
Theory:
Nearly all Linux distributions are compliant with a universal standard for filesystem directory
structure.
The symbol / is used to indicate the root directory in the filesystem hierarchy defined by the
FHS.
When a user logs in to the shell, they’ll be brought to their own user directory in /home.
The FHS defines /home as containing the home directories for regular users. (root has its own
home directory in /root, also specified by the FHS.)
Because default, common-sense locations are provided for many different kinds of files,
organisation of files for different purposes is simplified.
Permissions
On a system with multiple user accounts, determining who is allowed to interact with what
files is important.
Linux supports unix-style filesystem permissions, which restricts who can read and write
certain files.
Problem Statements:
1. Using a single command change from current directory to home directory.
2. Remove a directory using absolute pathname.
3. Create empty files myfile and yourfile under Present Working Directory.
4. Edit the content of myfile
5. Copy the contents of myfile into yourfile
6. Remove the file myfile
7. Create a hard link for yourfile
8. List the content of the present directory
9. Create the directory “test “ under current directory and move myfile and yourfile
into it
10. Remove the directory test along with the files in it using single command.
11. Rename the myfile to currentfile.
12. Write the command to create alias name for a file.
13. Is there any command available to get back a deleted file?
14. Can you remove a directory with files by using a single command.
15. Create a new file system by using mkfs command.
EXPERIMENT NO 3
Title: Documentation in Linux
Aim: To understand the use of man and info command.
Theory:
Linux man pages can be an extremely helpful resource, but you must understand their
purpose and limitations. Unlike the help systems in some OSs, Linux man pages are not
supposed to be tutorial in nature; they’re intended as quick references to help somebody
who’s already at least somewhat familiar with a command, confi guration fi le, or other OS
feature.
the man utility returns the entry in the section based on a search order typically specified by
the SECTION setting in the /etc/man_db.conf or the /etc/manpath.config configuration fi le
(depending on your distribution). You can override this behaviour by passing a section
number before the keyword. For instance, typing man passwd returns information from
manual section 1 on the passwd command, but typing man 5 passwd returns information
from manual section 5 on the /etc/passwd fie format
Problem Statements:
Getting Help Using man Pages
Theory:
Redirection is a feature in Linux such that when executing a command, you can change the
standard input/output devices. The basic workflow of any Linux command is that it takes an
input and give an output.
These files are always present whenever a program is run. As explained before a file
descriptor, is associated with each of these files.
File File Descriptor
By default, error stream is displayed on the screen. Error redirection is routing the errors to a
file other than the screen.
Problem Statements:
1. Redirect the output from one file to the input of another file
2. list directories and store both error and standard output into a file error
3. Sort the output of ls command output as per the months and save the output in the
file result.txt
4. Show the first ten entries of the ls command output in a file myfile
5. Write the command to display the output of ls command on the screen and also save
the output in a file result.txt.
6. Create a empty text file
7. Edit the file and enter the data into the file
a. Search for a particular word in the file
b. Copy the entire line and past it into the last line of the file.
c. Search and replace a particular word in a text file
d. Edit the the last word of each line in the file without using arrow key
8. Open the text file in read only format
EXPERIMENT NO 5
Title: Managing Local Linux Users and Groups
Aim: To understand Managing Local Linux Users and Groups commands.
Theory:
Problem Statements:
1. Login as a normal user
2. Create file test
3. Find the permissions of file test
4. Change the ownership of the file to usr1
5. Find the current umask setting
6. Change the umask setting
7. Create file test1
8. Find out the difference
9. Switch to Super User Account
10. Change group of file test
11. Change ownership and group of file test1 with a single command
12. Change the ownership of all the files in user1’s home directory with a single command
13. Create a file abc and turn the execute bit on
14. Set setuid permission on the file abc
15. Determine if the setuid permission is enabled on the file abc
16. Create a directory testdir
17. Set setgid permission on the testdir
Logout and login as user1
19. Create a file testfile in testdir
20. Verify the ownership and the group of the testfile
21. Switch to Superuser account
22. Create a public directory dir1
23. Set stickybit (save text attribute) on dir1
24. Logout and login as a normal user user1
25. Create a file userfile1 in dir1
26. Login as a different user user2
27. Try to edit or remove the file
28. Temporarily disable user logins
29. Login as root and create groups as dba with id 501 & stud with id 555
30. Create the following list of users
31. User name UID GID Working Shell Secondary Comments Group
Mac1 501 501 Bourne shell 555 Mac1 user
Mac2 502 501 C shell NULL Mac2user
Mac3 503 501 BASH Shell 555 Mac3 user
User1 504 555 Bourne shell NULL User1 user
User2 505 555 Bash Shell NULL User2 user
Shut ?????? ??????? ?????? NULL Shutdown the system
using the user id shut
32. Examine the content of the /etc/passwd file.
33. Examine the content of the /etc/shadow file. Name the text that is found in the second
field for the users created.
34. Set password for the users mac1, mac2, mac3 & shut.
35. Select user2 from the list of users. Change the passwd aging information for user2 so that
it matches the following information.
Max inactive 2 days
Expiry 4 days
Now change the system date increase by 5 days
36. Logout of login session. Attempt to log as user2. What happens?
37. Change the shell for the user2 to Bourne shell.
38. Delete user2 including his home directory and his comments.
39. Lock the user1 with the help of a single command.
EXPERIMENT NO 6
Title: Controlling Access to Files with Linux File System Permissions
Theory:
Example:
-rwxrwxrwx 1 student admins 7083 Jun 11 23:22 test.txt-rw-r--r-- 1 root root 0 Sep 12 12:40
code.c
User (U), group (G) and others (O) can read, write and execute the test.txt file
Commands in focus:
Setuid bit
The setuid bit indicates that when running the executable, it will set its permissions to that of
its owner, instead of setting it to the user who launched it. It can be identified from “s” symbol
For example:
srw-r — r — 1 root root 0 Sep 12 12:40 welcome
Note solution :
(Hint : https://blog.pentesteracademy.com/practice-linux-permissions-basics-with-13-
easy-questions-part-i-75aeaf299ebf
https://blog.pentesteracademy.com/practice-linux-permissions-basics-with-7-
activities-part-ii-3c6a212e64b9)
EXPERIMENT NO 7
Title: Manage Basic Storage
Theory:
There are many tools available to manage storage in Linux. However, only a handful are used
for day-to-day maintenance and administration. In this guide, we will cover some of the most
commonly used utilities for managing mount points, storage devices, and filesystems.
Often, the most important information you will want to find out about the storage on your
system is the capacity and current utilization of the connected storage devices.
To check how much storage space is available in total and to see the current utilization of
your drives, use the df utility. By default, this outputs the measurements in 1K blocks, which
isn’t usually too useful. Add the -h flag to output in human-readable units:
df -h
Copy
Output
A block device is a generic term for a storage device that reads or writes in blocks of a
specific size. This term applies to almost every type of non-volatile storage, including hard
disk drives (HDDs), solid state drives (SSDs), flash memory, etc. The block device is the
physical device where the filesystem is written. The filesystem, in turn, dictates how data and
files are stored.
Before you can use a new disk, you typically have to partition it, format it with a filesystem,
and then mount the drive or partitions. Partitioning and formatting are usually one time
procedures, so we won’t discuss them here.
The most basic way to use mount is to pass in a formatted device or partition and the mount
point where it is to be attached:
Copy
The mount point, the final parameter which specifies where in the file hierarchy the new
filesystem should be attached, should almost always be an empty directory.
Problem Statements:
Theory:
ifconfig Command
ifconfig is a command line interface tool for network interface configuration and also used to
initialize an interfaces at system boot time. Once a server is up and running, it can be used to
assign an IP Address to an interface and enable or disable the interface on demand.
It is also used to view the status IP Address, Hardware / MAC address, as well as MTU
(Maximum Transmission Unit) size of the currently active interfaces. ifconfig is thus useful
for debugging or performing system tuning.
To list all interfaces which are currently available, whether up or down, use the -a flag.
$ ifconfig -a
IP Command
ip command is another useful command line utility for displaying and manipulating routing,
network devices, interfaces. It is a replacement for ifconfig and many other networking
commands
o temporarily assign IP Address to a specific network interface (eth0), type.
$ sudo ip addr add 192.168.56.1 dev eth0
ifup command actives a network interface, making it available to transfer and receive data.
ifquery command used to parse the network interface configuration, enabling you to receive
answers to query about how it is currently configured.
Ethtool Command
ethtool is a command line utility for querying and modifying network interface controller
parameters and device drivers. The example below shows the usage of ethtool and a
command to view the parameters for the network interface.
Ping Command
ping (Packet INternet Groper) is a utility normally used for testing connectivity between
two systems on a network (Local Area Network (LAN) or Wide Area Network (WAN)). It
use ICMP (Internet Control Message Protocol) to communicate to nodes on a network.
To test connectivity to another node, simply provide its IP or host name, for example.
$ ping 192.168.0.103
You can also tell ping to exit after a specified number of ECHO_REQUEST packets, using
the -c flag as shown.
Route Command
route is a command line utility for displaying or manipulating the IP routing table of a Linux
system. It is mainly used to configure static routes to specific hosts or networks via an
interface.
You can view Kernel IP routing table by typing.
$ route
There are numerous commands you can use to configure routing. Here are some useful ones:
Problem Statements:
1. Add a route to the 192.0.2.0/24 network that uses the gateway running on 198.51.100.1
2. Use the hostname command to determine your hostname
3. Determine your IP and MAC addresses( ifconfig)
4. display all your network interfaces(hint: ip a)
5. Run nmcli d show and record the output
6. Use the arp command to determine if your neighbour's IP address is listed. If not, ping your
neighbour's IP address and then run the arp command again. (Alternatively, you can use
arping.)
7. Use the tcpdump command to analyze network traffic. Watch the network traffic for a few
minutes then summarize what you have seen. For example, in the Terminal window, if your
Ethernet card is called eth1, run sudo tcpdump -i eth1 (The sudo command is required
because tcpdump requires administrator privileges.) Then, start Firefox and log on to
Blackboard, for example.
8. Use the tracepath or traceroute command to find a route to various hosts on the Internet.
For example, tracepath ritindia.edu
(http://technology.niagarac.on.ca/courses/ctec1767/lab9/ctec1767-2017WS-lab9-Linux.pdf)
EXPERIMENT NO 9
Title: Archiving and Copying Files between Systems
Aim: To understand and learn about Archiving and Copying Files between Systems in linux
Theory:
tar and gzip provide a standard interface for creating archives and compressing files on
Linux. These utilities take a large number of files, save them together in an archive, and
compresses the archive to save space. tar does not compress files by itself. Used in
conjunction with gzip, an archived file can be compressed to reduce disk space. The resulting
archived file has the file extension, tar.gz and is sometimes called a “tarball”.
Flag Function
These are the basics for working within the command line. Be sure to check the man
pages man tar for a more detailed listing of possible flags when compressing and
extracting files
Problem Statements:
1. Create three sample directories with some files to use with the tar command.
2. Use the tar command to backup all three directories into single tar file.
3. Use the tar command to verify that the files are on the tape and in a single tar
file.
4. Use the tar command to backup the sample directories into four different
files.
5. Verify the number of tar files using the tar command.
6. Backup a directory using cpio.
7. Restore the files which are backuped in the floppy.
8. Back up a floppy to a floppy using dd.
9. Restore from floppy to home directory using dd.
EXPERIMENT NO 10
Title: Installing and Updating Software Packages
Aim: To understand and learn about Installing and Updating Software Packages
Theory:
One of the most difficult things to get used to in the Linux world is installing new software
packages. In the world of Windows, every program comes with a Setup.exe program that
asks you some very easy questions and takes care of the job for you. While Linux software
can be almost that easy to install, you will sometimes find software that seems to fight every
step of the way. I can’t cover all the problems you might run into, but I’ll try to give you the
basics and a few pointers to help get you over the rough spots.
The standard Linux package format (according to the Linux Standard Base) is RPM. RPM
is a packaging system originally developed by Red Hat and widely used in the Linux
community. Distributions using it include Fedora, Mandriva, Red Hat (naturally), and SUSE.
An RPM package file normally will be named something like program-version-other.rpm
Another popular package format is DEB, the Debian software package. Debian packages and
the Advanced Packaging Tool (APT) were the first to introduce several advanced features
that are now common, such as automatic dependency resolution and signed packages. Debian
packages are used by Debian GNU/Linux (naturally), and distributions based on it, including
Ubuntu, Knoppix, and Mepis. A Debian package file normally will be named something
like program-version-other.deb
There is a broad array of tools for working with DEB packages, but the one you will
commonly use is apt-get, arguably the easiest of Linux package management tools. apt-get is
so easy because it not only keeps track of what packages are installed, but also what other
packages are available. It will even download them from the Internet for you (if properly
configured).
Although the repositories that contain installable packages might live on the Internet or on a
disc somewhere, APT keeps a local database on your hard drive with a list of all available
packages and where to find them. This database needs to be explicitly updated. To update the
APT database:
apt-get update
A common idiom is to update your package database, and then upgrade all the packages that
have patches or security updates to install. The following command will do this all at once.
For a more indepth apt-get tutorial and other resources, see Managing Software with APT
and dpkg.
yum does for RPM packages roughly what apt-get does for Debian packages. Like apt-
get, yum can download and install packages from a configured repository.
yum does not keep a local copy of your package database by default, so normally there is no
need to update it. To install all available security patches and bug fixes, use this command:
yum update
Mandriva: urpm
Mandriva Linux (formerly Mandrake and Connectiva) has a toolset similar to APT
called urpmi. To install software:
urpmi ${packagename}
To remove software:
urpme ${packagename}
urpmi.update -a
urpmi --auto-select
For a more indepth yum tutorial and other resources, see Managing Software with urpm.
Tar Balls
No, this is not a naughty term! A tar ball is a (usually compressed) archive of files, similar to
a Zip file on Windows or a Sit on the Mac. Tar balls come in files that end in .tar, .tar.gz, .tgz,
or something along these lines. To unpack a tar ball, use this command.
The parameters are x to extract files, z to filter through gzip for decompression (leave this off
if the file does not have a gz extension), v for verbose mode so you can tell what’s going
on, f indicating there will be a filename to follow. You may want to create an alias called
“untar” that feeds in these options if you have a hard time remembering command line
options as I do.
This command will not install the software, it will only extract the archived files. It is your
job then to find the README file or INSTALL file and read its instructions for installation.
If the archive contains binaries there will usually be a setup script (often called install.sh) that
you must execute as SuperUser.
Very often, software delivered in tar balls is not in executable form, but in source code,
which must first be compiled before it can be installed. For more details on this,
see Installing Software from Source Code.
Other Systems
Some other Linux distributions have their own way of managing packages, notably SUSE.
SUSE uses RPM as its native package format, but has its own high level tool to manage
system software installation.
SUSE Linux uses a tool called yast (which allegedly is an acronym for Yet Another Setup
Tool) to perform all kinds of system administration tasks, including installing sof
Problem Statements:
1. On serverb configure a software repository to obtain updates. Name the
repository as errata and configure the repository in
the /etc/yum.repos.d/errata.repo file. It should access
http://content.example.com/rhel8.0/x86_64/rhcsa-practice/errata. Do not
check GPG signatures.
2. On serverb, install new package xsane-gimp and the Apache HTTP Server
module from the 2.4 stream and the common profile.
3. For security reasons, serverb should not be able to send anything to print.
Achieve this by removing the cups package. Exit from the root account.
4. The start script downloads the rhcsa-script-1.0.0-1.noarch.rpm package in
the /home/student directory on serverb. Confirm that the package rhcsa-
script-1.0.0-1.noarch.rpm is available on serverb. Install the package. You will
need to gain superuser privileges to install the package. Verify that the
package is installed. Exit from serverb.
SOLUTION
1.1. From workstation use the ssh command to log in to serverb as the student
user.
1.2. Use the su - command to switch to the root user. The password is redhat.
2.1. Use the yum list command to list the available packages for xsane-gimp.
2.2. Install the latest version of the xsane-gimp package using the yum
install command.
2.3. List available modules and streams. Look for the httpd module. Use
the yum install command to install the httpd module with the 2.4 stream and
the common profile.
3. For security reasons, serverb should not be able to send anything to print.
Achieve this by removing the cups package. Exit from the root account. 3.1.
Use the yum list command to list the installed cups package.
4.3. Use the rpm command to verify that the package is installed.