Skill Lab Linux Lab Manual _NG
Skill Lab Linux Lab Manual _NG
Laboratory Manual
(Faculty Copy)
Semester VI Class TE
Course Name Skill Laboratory: Linux and Networking & Server Configuration
Vidyavardhini’s College of Engineering
& Technology
Vision
To be a premier institution of technical education;
always aiming at becoming a valuable resource for
industry and society.
Mission
●To provide technologically inspiring environment
for learning.
●To promote creativity, innovation and professional
activities.
●To inculcate ethical and moral values.
●To cater personal, professional and societal needs
through quality education.
Department Vision:
Vidyavardhini’s College of Engineering & Technology
To contrive educational and research environments to serve industry and society needs in the
field of electronics and telecommunication engineering.
Department Mission:
● To enrich soft skills, ethical values, environmental and societal awareness.
● To develop technical proficiency through projects and laboratory work.
● To encourage students for lifelong learning through interaction with the outside
world.
PEO2: The graduates will develop a habit of continuous learning while working in
multidisciplinary environment.
PEO3: The graduates will grow as an individual with proficiency in technical skills, ethical
values, communication skills, teamwork and professionalism.
PSO1: To apply the knowledge of Electronics and Communication to analyse, design and
implement application specific problems with modern tools.
PSO2: Adapt emerging technologies with continuous learning in the field of electronics and
telecommunication engineering with appropriate solutions to real life problems.
Program Outcomes (POs):
Engineering Graduates will be able to:
● PO1. Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the solution of complex
engineering problems.
● PO2. Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
● PO3. Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.
Vidyavardhini’s College of Engineering & Technology
1. Syllabus
5. List of Experiments
1. Linux installation process using any one following method: CD-ROM, Network
installation or Kickstart installation.
5.
6.
7..
8.
9.
Course Objectives
Vidyavardhini’s College of Engineering & Technology
Course Outcomes
At the end of the course, students will be able to: Action verb Bloom
Level
ECL604.4 Write shell script programs for conditional and write Apply
looping statements in bash. (Level 3)
EC EC EC EC EC EC
L6 L L L L L
No
04. 60 60 60 604 604
1 4.2 4.3 4.4 .5 .6
2
Explore the internal and external commands of Linux. 3 - - - - -
11
To setup and configure Linux Mail Server. - - - - - 3
12
Configuration of DNS server with domain name in Linux. - - - - 3 -
INDEX
Experiment No.: 1
Linux Installation
Aim: To install Linux using CD-ROM Network installation, or Kickstart
installation
Theory: Installation Steps of Ubuntu 20.04 LTS
Step:1 Download the ISO file using the following links
https://ubuntu.com/download/desktop
Vidyavardhini’s College of Engineering & Technology
Once the iso file has been downloaded, burn it into DVD or USB drive and make it
bootable. Save the file to a location of your choice
Option 2: Create
You’ll need to install a third-party utility called Rufus to create a USB
bootable drive.
1. Download the Rufus utility. Scroll down to the download section and click
the link to download the latest version of Rufus.
3. A pop-up dialog opens. You will be prompted whether you want to check
for online updates. Select No.
4. The Rufus utility launches. Plug in the USB drive – you should see the
drive pop up in the device field.
6. Click Start.
3. To manually configure the boot order, tap the boot menu key about once or
twice per second as soon as the computer powers on.
The boot menu key may be different depending on your computer
manufacturer. Below is a list of common boot keys associated to a brand:
Asus F8 or Esc
Acer F12, F9 or Esc
Vidyavardhini’s College of Engineering & Technology
Compaq F9 or Esc
Dell F12
eMachines F12
Fujitsu F12
HP F9 or Esc
Lenovo F8, F10 or F12
Samsung F2, F12 or Esc
Toshiba F12
4. Once you see your boot menu, use the arrows to pick the Ubuntu media to
boot from. For a DVD, the entry will usually have DVD or Optical in the
name. USB is usually labeled USB.Your system should start loading the
Ubuntu live disc menu.
Disk Partitioning
Next, you’ll be presented with an Installation Type dialog. You can wipe the
hard drive clean prior to installing Ubuntu by clicking Erase disk and install
Ubuntu. If you go this route, skip ahead to the next step.
Advanced users may want to edit Advanced Features. Use this to specify
your own disk partitions or set other advanced options:
● Use LVM with the new Ubuntu installation: LVM stands for Logical
Volume Management. This is a tool for dynamically managing different
virtual drives on your system. It’s much like an enhanced version of
the gparted tool.
● Encrypt the new Ubuntu installation for security: This will encrypt the
drive’s contents. You’ll choose a security key, which will be required to
decrypt and use the drive.
Vidyavardhini’s College of Engineering & Technology
● Experimental: Erase disk and use ZFS: ZFS refers to Zettabyte File System,
but it has grown into a hybrid file system and volume manager. Since it’s
still being tested, avoid this setting on mission-critical production systems.
If you’d rather create your own hard drive partitions, click Something Else.
The next screen will allow you to create your own partition table and logical
drives. This lets you divide a physical hard drive into different partitions. The
operating system sees partitions as individual drives.
Click Continue to apply your changes to the drive partitions.
You’ll be asked to Write changes to disks? None of the options you’ve
selected are permanent until you click Continue on this screen.
Click Continue to proceed.
Select Time Zone
Once the system formats the disk partitions, the installer will ask Where are
you?
Type the nearest large city into the box, and the system will set your local
time zone.
Click Continue.
Create User Account
Next, you’ll need to configure a user account. Fill in the following fields:
The system should boot into your fresh install of Ubuntu 20.04.
Conclusion:
.
Vidyavardhini’s College of Engineering & Technology
Experiment No: 2
hello.txt TRIAL2
cat 1) It can also use to create new file with content as shown below.
cat> hello.txt
hello from Shamika
2) It can also use to append the data into existing file as shown
below.
cat>>hello.txt
3) It is used to concatenate files.
napster@napster-Veriton-Series:~/TRIAL$ cat hello.txt hi.txt
hello from Shamika
How are you?
Welcome to Os Lab.
file permission bits of mask are used), and returns the previous
value of the mask.
b1@comp:~$ umask u=rwx,g=rwx,o=rx
-S
Conclusion:
Post Experiment 1. Comment on the basic difference between internal and external
questions: commands.
2. What are the scheduling techniques in Linux?
Experiment No. 3
Aim: Explore the system calls open, read, write, close, getuid, getgid, getegid,
Vidyavardhini’s College of Engineering & Technology
geteuid o Linux.
Effective user The effective UID (euid) of a process is used for most access checks. It
ID is also used as the owner of files created by that process. The effective
GID (egid) of a process also affects access control and may also affect
file creation, depending on the semantics of the specific kernel
implementation in use and possibly the mount options used.
Open: Used to Open the file for reading, writing, or both. Open() returns file
descriptor 3 because when main process is created, then fd 0, 1, 2 are
already taken by stdin, stdout, and stderr. So first unused file
descriptor is 3 in the file descriptor table.
int open(const char *pathname, int flags);
Close: Tells the operating system you are done with a file descriptor and Close
the file which pointed by fd.
int close (int fd);
Parameter
fd:file descriptor
Return
on success.
-1 on error.
read: Read data from one buffer to file descriptor, Read size bytes from the
file specified by fd into the memory location.
size_t read (int fd, void* buf, size_t cnt);
Parameters
fd: file descriptor
buf: buffer to read data from
cnt: length of buffer
Returns: How many bytes were read
return the Number of bytes read on success
return 0 on reaching the end of the file
return -1 on error
return -1 on signal interrupt
Write: Write data from a file descriptor into the buffer, Writes the bytes stored
in buf to the file specified by fd. The file needs to be opened for write
operations
size_t write (int fd, void* buf, size_t cnt);
Parameters
fd: file descriptor
buf: buffer to write data to
cnt: length of buffer
Returns: How many bytes were written
return the Number of bytes written on success
return 0 on reaching the end of the file
return -1 on error
return -1 on signal interrupt
Vidyavardhini’s College of Engineering & Technology
Conclusion:
Code:
#include<stdio.h>
#include <unistd.h>
#include<string.h>
#include<fcntl.h>
Vidyavardhini’s College of Engineering & Technology
int main()
{
char data[64];
printf("getuid : %d \n",getuid());
printf("geteuid : %d \n",geteuid());
printf("getgid : %d \n",getgid());
printf("getegid : %d \n",getegid());
int fd = open("/home/shraddha/SYCALL.txt", O_CREAT | O_RDWR |
O_APPEND);
printf("fd : %d\n", fd);
int read1 = read(fd,data,64);
printf("%d\n",read1);
int w = write(fd,"smita",strlen("smita"));
close(fd);
}
Code for Open() System Call
d9@d9-desktop:~$ touch text.txt
d9@d9-desktop:~$ cat text.txt
d9@d9-desktop:~$ cat>text.txt
Hi this is my new document
How are you?
cat > text.txt
d9@d9-desktop:~$ nano new.c
#include<fcntl.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/stat.h>
int main()
{
int n, fd, fd1;
char buf[30];
fd=open("text.txt", O_RDONLY);
n=read(fd, buf, 20);
fd1=open("target", O_CREAT|O_WRONLY,0642);
write(fd1, buf, n);
}
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
printf("PID of exp.c= %d\n", getpid());
char *args[]={"Hello","C", "Programming", NULL};
execv("./hello",args);
printf("Back to exp.c");
return 0;
}
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
printf("We are in hello.c\n");
printf("PID of hello.c= %d\n", getpid());
return 0;
}
d9@d9-desktop:~$ gcc -o exp exp.c
d9@d9-desktop:~$ gcc -o hello hello.c
d9@d9-desktop:~$ ./exp
OUTPUT:
getgid : 1000
getegid : 1000
fd : 3
0
shraddha@shraddha-Inspiron:~$ ./s
getuid : 0
geteuid : 0
getgid : 0
getegid : 0
fd : 3
10
PID of exp.c= 5445
We are in hello.c
PID of hello.c= 5445
Vidyavardhini’s College of Engineering & Technology
Experiment No. 4
Aim Write Shell Scripts to do the following:
1. Display the top 10 processes in descending order.
2. Display processes with the highest memory usage.
3. Display the current logged-in user and log name.
4. Display the current shell, home directory, OS type, OS version, release
number, kernel version, current path setting, and current working directory.
Theory The shell is the operating system's command-line interface (CLI) and
interpreter for the set of commands that are used to communicate with the
system. A shell script is usually created for command sequences in which a
user has a need to use repeatedly in order to save time.
Shell is a user program or its environment is provided for user interaction. It
is a command prompt within Linux where you can type commands. It is a
program that takes your commands from the keyboard and gives them to the
OS to perform. Shell is not part of system KERNAL but it uses system
KERNAL to execute programs, create files, etc. A Shell Script is a text file
that contains a sequence of commands for a UNIX-based OS. It is called a
Shell Script because it combines into a "Script" in a single file a sequence of
commands, that would otherwise have to be presented to the system from a
keyboard one at a time. A Shell Script is usually created for command
sequences for which a user has a repeated need. You initiate the sequence of
commands in Shell Script by simply entering the name of the Shell Script on
a command line.
To use a particular Shell type the Shell name at the command prompt. Eg:-
$csh - It will switch the current Shell to C Shell. To view the current Shell
that is being used, type echo $ SHELL at the command prompt.
Conclusion
Vidyavardhini’s College of Engineering & Technology
Code #!/bin/bash
#Display current logged in user and logname.
Vidyavardhini’s College of Engineering & Technology
:
Vidyavardhini’s College of Engineering & Technology
Objective: Since Linux is a multi-user operating system, several people may be logged in
and actively working on a given machine at the same time. Security-wise, it is never a good
idea to allow users to share the credentials of the same account. In fact, best practices dictate
the use of as many user accounts as people needing access to the machine.
At the same time, it is to be expected that two or more users may need to share access to
certain system resources, such as directories and files. User and group management in Linux
allows us to accomplish both objectives.
Theory:
useradd create a new user or update default new user information , useradd is a
low level utility for adding users.
groupadd create a new group , The groupadd command creates a new group
account using the values specified on the command line plus the default
values from the system. The new group will be entered into the system
files as needed.
groupdel entries that refer to GROUP. The named group must exist
who show who is logged on , Print information about users who are currently
logged in.
whoami print effective userid
passwd change user password
The passwd command changes passwords for user accounts. A normal
user may only change the password for his/her own account, while the
superuser may change the password for any account. passwd also
changes the account or associated password validity period.
Linux shell script to add a user with a password
useradd -m -p EncryptedPasswordHere username
Where,
-m : The user’s home directory will be created if it does not exist.
-p EncryptedPasswordHere : The encrypted password, as returned by crypt().
username : Add this user to the Linux system,
Vidyavardhini’s College of Engineering & Technology
crypt() is a one-way hash function. The PLAINTEXT ($plain) and SALT are turned into a
short string, called a digest, which is returned. The same PLAINTEXT and SALT will always
return the same string, but there is no (known) way to get the original PLAINTEXT from the
hash. Small changes in the PLAINTEXT or SALT will result in large changes in the digest.
Sample output:
sa.KT9zrGYeg2
The Perl command will display the encrypted password (sa.KT9zrGYeg2) on screen. The
Perl crypt() function is a one way encryption method meaning, once a password has been
encrypted, it cannot be decrypted. The password string is taken from the user and encrypted
with the salt and displayed back on computer screen. We can store an encrypted password
using the following syntax:
password="1YelloDog@"
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
echo "$pass"
Sample outputs
sa.KT9zrGYeg2
Vidyavardhini’s College of Engineering & Technology
Code:
b1@comp:~$ ls -l a
-rwxrwxrwx 1 b1 b1 72 Feb 16 16:09 a
guest-dR7woG
b1@comp:~$ who
b1 :0 2018-02-16 15:37 (:0)
b1 pts/0 2018-02-16 16:16 (:0)
b1@comp:~$ whoami
b1
#!/bin/bash
# Script to add a user to Linux system
# -------------------------------------------------------------------------
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to
add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
Vidyavardhini’s College of Engineering & Technology
fi
Grant executable permissions
Executable permissions must be granted to the files to make them run or execute on the
system. We could also use “777” instead of “+x” in the chmod command. Also please run the
script as root to
chmod +x file_name.sh
Run the script
For root owners
./file_name.sh
Example 1:
./file_name.sh
For non-root owners
sudo ./file_name.sh
Example:
sudo ./file_name.sh
Delete a user
Example:
deluser Smita
Output:
Conclusion: Comment on the role of user and group management commands of Linux.
Vidyavardhini’s College of Engineering & Technology
Experiment No.6
Write a shell script program to check login details.
Date of Performance:
Date of Submission:
Objective: Linux is a multi-user operating system, several people may be logged in and
actively working on a given machine at the same time. It is to be expected that two or more
users may need to share access to certain system resources, such as directories and files. We
can identify the number of users logged in, past users on the Linux system.
Vidyavardhini’s College of Engineering & Technology
Theory:
Every operating system provides a feature of multiple user accounts. Linux-based operating
systems have some commands or functionalities to check user accounts’ details and change
them. This ability is mainly used by the admin account user that is the root user, to provide
permissions and access to different users. The admin can also check how many users are
currently logged in, how many are logged out, and the login time. Here in this article, we
will explore all these ways and also write a shell script to complete these tasks efficiently.
Id The id command is used to print the user and group information for the
specified USER.
-a ignore, for compatibility with other versions
-Z, --context print only the security context of the process
-g, --group print only the effective group ID
This id command has produced all the user identifiers, group identifiers,
and groups. If you want only a group identifier, use the below command.
groups This will print the group to which the specified user belongs. If no specific
username is given, it will search for the current users. Use the below
command for the current user.
getent This command displays entries from the databases.
getent protocols Fetch the list of user accounts on a Linux system (stored in a database
known as ‘passwd’). This will show all the user accounts, regardless of the
getent passwd
type of name service being used. The databases it usually searches in are:
getent -V ahosts, ahostsv4, ahostsv6, aliases, ethers (Ethernet addresses), group,
gshadow, hosts, netgroup, networks, passwd, protocols, rpc, services, and
shadow.
lslogins: To see all the usernames and user ids. This provides a list of several
features like UID, USER, LAST-LOGIN, etc.
Vidyavardhini’s College of Engineering & Technology
who : To show who is logged-on. This lists the users with id and the time and
date of user login.
-a, --all same as –b, -d, --login, -p, -r, -t, -T, -u
w: w command shows the logged-on user accounts and also shows what they
are doing.
-h,
--no-header do not print header
-u,
--no-current ignore current process username
last or lastb: The commands last and lastb shows a listing of last logged in users
-<number> how many lines to show
This provides all the login details of several users according to date and
time.last
lastlog: This will produce a report of all the recent login users. This can also create
a single-user report if specified.
-b, --before
print only lastlog records older than DAYS
DAYS
clear lastlog record of a user (usable on
-C, --clear
This tells about the latest log of the users.
Lastlog
Vidyavardhini’s College of Engineering & Technology
Shell Script Now we will create a shell script using some above-mentioned commands
to get user details. We are approaching the solution in a way that the user
is asked for input by given suggestions. That input will be then used to
check against the available cases, and then the matched case will be
allowed to run.
Open gedit file: Open any editor according to your preferences, we have used gedit editor
because of its simple user interface and the color combination present.
gedit user-accounts.sh
Code: Here in the userAccounts.sh we will write our code, and use switch cases
to compare the user input. We have used commands like lslogins, who,
groups, etc. which will help us to satisfy the user requirements. You can
find the use of these commands extended above. So, let us begin the script.
Code:
#!/bin/bash
#here we are going to develop a script for various options on user accounts
echo -e "\n
[ 1 ] for listing all the user accounts name \n
[ 2 ] for counting the number of logged-in user accounts \n
[ 3 ] for listing the names of currently logged-in users\n
[ 4 ] for checking the groups to which the current user belong \n"
Vidyavardhini’s College of Engineering & Technology
esac
Output:
Conclusion:
Experiment No.7
Vidyavardhini’s College of Engineering & Technology
Objective: Linux bash shell is an interpreter. Shell program provides access to an operating
system's components. The shell gives users (or other programs) a way to get "inside" the
system; the shell defines the boundary between inside and outside. Here we can calculate a
factorial of a given number using three methods.
Theory:
The factorial of a number is the function that multiplies the number by every natural number
below it. Symbolically, factorials can be represented as "!". So, n factorial is the product of
the first n natural numbers and is represented as n!
Here we are going to calculate the factorial of a number. The Factorial of a non-negative
integer is the multiplication of all integers smaller than or equal to n.
For example factorial of 5 is 5*4*3*2*1 which is 120.
factorial()
product=$1
echo $product
else
f=$((product -1))
# Recursive call
Vidyavardhini’s College of Engineering & Technology
f=$(factorial $f)
f=$((f*product))
echo $f
fi
# main program
read num
echo 1
else
factorial $num
fi
Output:
Approach:
● Get a number
● Use for loop to compute the factorial by using the below formula
● fact(n) = n * n-1 * n-2 * …
Vidyavardhini’s College of Engineering & Technology
Output:
● Get a number
● Use do-while loop to compute the factorial by using the below formula
● fact(n) = n * n-1 * n-2 * .. 1
● Display the result.
Output:
Conclusion: Comment on shell script program for calculating a factorial of a given number.
Vidyavardhini’s College of Engineering & Technology
Experiment No.8
Vidyavardhini’s College of Engineering & Technology
Aim Shell Script that accepts the hostname and IP address as command line
arguments and adds them to the /etc/hosts file.
Theory 1. ifconfig
Syntax: ifconfig
Examples:
1. ifconfig eth0
2. ifconfig lo
3. ifconfig wlan0
3) host Command
Linux host command displays domain name for given IP address or vice-
versa. It also performs DNS lookups related to the DNS query. The host
command's default behavior displays a summary of its command-line
arguments and supported options.
Syntax:
1. host <name>
where,
Vidyavardhini’s College of Engineering & Technology
Example:
Output:
Output:
Conclusion
Post 1. How does the script handle the situation where the hostname or IP address
experiment is already present in the /etc/hosts file?
quiz
2. What permissions are required to modify the /etc/hosts file, and how can
the script ensure it has the necessary permissions to make changes?
#!/bin/bash
read -p "Enter host: " hostname
read -p "Enter IP address of the host: " ip
sed -i.bkp "$ a $hostname $ip" /etc/hosts
Code #!/bin/sh
# PATH TO YOUR HOSTS FILE
ETC_HOSTS=/etc/hosts
# DEFAULT IP FOR HOSTNAME
IP="127.0.0.1"
# Hostname to add/remove.
HOSTNAME=$1
function removehost()
{
Vidyavardhini’s College of Engineering & Technology
Output
Vidyavardhini’s College of Engineering & Technology
Output:
testhost1 192.168.1.2
Final Script:
#!/bin/sh
ETC_HOSTS=/etc/hosts
IP="127.0.0.1"
# Hostname to add/remove.
HOSTNAME=$1
function removehost()
then
else
fi
function addhost()
HOSTNAME=$1
Vidyavardhini’s College of Engineering & Technology
HOSTS_LINE="$IP\t$HOSTNAME"
then
else
then
else
fi
fi
OUTPUT:
Conclusion:
Experiment No.9
Aim Write awk script to find the number of characters, words, and lines in a file.
Vidyavardhini’s College of Engineering & Technology
Theory Awk is a scripting language used for manipulating data and generating
reports. The awk command programming language requires no compiling and
allows the user to use variables, numeric functions, string functions, and
logical operators.
Awk is a utility that enables a programmer to write tiny but effective
programs in the form of statements that define text patterns that are to be
searched for in each line of a document and the action that is to be taken when
a match is found within a line. Awk is mostly used for pattern scanning and
processing. It searches one or more files to see if they contain lines that match
the specified patterns and then performs the associated actions.
Awk is abbreviated from the names of the developers – Aho, Weinberger, and
Kernighan.
WHAT CAN WE DO WITH AWK?
1. AWK Operations:
(a) Scans a file line by line
(b) Splits each input line into fields
(c) Compares input line/fields to pattern
(d) Performs action(s) on matched lines
2. Useful For:
(a) Transform data files
(b) Produce formatted reports
3. Programming Constructs:
(a) Format output lines
(b) Arithmetic and string operations
(c) Conditionals and loops
Syntax:
awk options 'selection _criteria {action }' input-file > output-file
Options:
-f program-file : Reads the AWK program source from the file
Vidyavardhini’s College of Engineering & Technology
Procedure 1. Default behavior of Awk: By default Awk prints every line of data from the
specified file.
$ awk '{print}' newdata.txt
smita_patil@cloudshell:~ (alien-bricolage-340809)$ awk '{print}' newdata.txt
Output:
LinuxLab Practical Termwork 50
DBMS Theory Oral 25
Datastructure Theory Oral 25
Maths Tutorial termwork 25
CS Oral Practical 25
2. Print the lines which match the given pattern.
$ awk '/oral/ {print}' newdata.txt
smita_patil@cloudshell:~ (alien-bricolage-340809)$ awk '/Theory/ {print}'
newdata.txt
Output:
Vidyavardhini’s College of Engineering & Technology
Conclusion
Post 1.How can you use AWK to extract specific columns from a text file or log
experimen file based on a delimiter
t quiz 2.Explain how AWK supports pattern matching. How would you use it to
filter lines containing a specific word or pattern from a file?
len=length($0)
total_len =total_len+len
print(NR,":\t",len,":\t",NF,$0)
words =NF
}
END{
print("\n total")
print("characters :\t" total_len)
print("lines :\t" NR)
}
Experiment No.10
Aim To setup and configure FTP Server with VSFTPD on Ubuntu 20.04
Theory FTP, or File Transfer Protocol, is a standard network protocol used for
transferring files between a client and a server over the internet or other
networks. It enables users to upload or download files, making it essential for
tasks such as website management and data exchange. FTP typically requires
authentication through a username and password, although some servers allow
anonymous access. It operates in two modes: active mode, where the client
listens for the server to connect, and passive mode, where the client connects
to the server, often used in firewalled environments. File transfers can be done
in binary mode for non-text files or ASCII mode for text files. Common
commands include get and put for downloading and uploading files, ls or dir
for listing directory contents, and cd for navigating server directories.
However, FTP is not secure as it transmits data, including credentials, in plain
text. For enhanced security, alternatives like FTPS, which uses SSL/TLS
encryption, or SFTP, which leverages SSH, are recommended. These secure
protocols ensure that file transfers are protected against unauthorized access.
FTP (File Transfer Protocol) is a standard network protocol used to transfer
files to and from a remote network. There are several open-source FTP servers
available for Linux. The most known and widely used are PureFTPd,
ProFTPD, and vsftpd. We’ll be installing vsftpd (Very Secure FTP Daemon), a
stable, secure, and fast FTP server. Although FTP is a very popular protocol,
for more secure and faster data transfers, we can use SCP or SFTP.
Procedure
Installing vsftpd on Ubuntu 20.04
The ftp service will automatically start once the installation process is
complete. To verify it, print the service status:
following:
The system should ask you to create a password for the new testuser account.
Replace ubuntu-ftp with the name of your system (taken from the command
line).
Log in using the testuser account and password you just set. You should now
be successfully logged in to your FTP server.
home directory.
Now, you can put any files you want to share via FTP into the /srv/ftp folder
(if you left it as the default), or the /srv/ftp/new_location/ directory (if you
changed it).
Find the entry labeled write_enable=NO, and change the value to “YES.”
Save the file, exit, then restart the FTP service with the following:
This allows the user to make changes inside their home directory.
Securing FTP
Numerous exploits take advantage of unsecured FTP servers. In response,
there are several configuration options in vsftpd.conf that can help secure your
FTP server.
chroot_local_user=YES
Instruct your FTP server to limit this list of users to their own home directories
by editing vsftpd.conf:
chroot_local_user=YES
chroot_list_file=/etc/vsftpd.chroot_list
By default, the list of blocked users from FTP access is stored in /etc/ftpusers.
To add blocked users, edit this file and add one user per line.
For this to work, users need to be set up with a shell account on the FTP
server. This will add a layer of secure encryption to your FTP traffic.
1. Start by creating a new certificate with openssl. To do so, run the command:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout
/etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem
3. Next, open your vsftpd.conf file in an editor and change the line
ssl_enable=NO to ssl_enable=YES:
ssl_enable=YES
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
Vidyavardhini’s College of Engineering & Technology
require_ssl_reuse=NO
ssl_ciphers=HIGH
pasv_min_port=40000
pasv_max_port=50000
Conclusion
Post
Experimen 1. How does FTP handle file transfer modes, and why is it important to choose
t quiz between ASCII and binary modes appropriately?
2.What security risks are associated with using standard FTP, and how do
secure alternatives like SFTP or FTPS mitigate these risks?
Vidyavardhini’s College of Engineering & Technology
Experiment No.11
● Mail user agent (MUA) is the GUI, the part that lets you write and
send emails, like Thunderbird or Outlook.
Vidyavardhini’s College of Engineering & Technology
● Mail transport agent (MTA) is the bit that moves the mail (as the
name suggests). MTAs like Sendmail and Postfix are the parts that
waft your communications from place to place through the ether.
● Mail delivery agent (MDA) is the component that sends out messages
sent to you on your local machine, so they get to the appropriate user
mailbox. Postfix-maildrop and Procmail are examples.
1. online mode is like having direct access to the Linux email server file
system.
2. offline mode feels like POP, where the client only connects to the
network to get their mail, and the server won’t keep a copy.
3. disconnected mode lets users keep cached copies of their emails and
the server keeps one too.
There are a few different implementations for IMAP and POP, with the most
prevalent being dovecot server, which offers both.POP3, POP3S, IMAP, and
IMAPS listen on ports 110, 995, 143, and 993 respectively.
For distributions based on Debian, like Ubuntu, you’d install them like this:
As you configure Linux mail server you will receive a prompt to choose how
you want to configure your Postfix mail server.
● No configuration
● Internet site
● Internet with smarthost
● Satellite system and Local only
Let’s go with the No configuration option for our Linux email server.
myhostname
Use this one to specify the hostname of the mail server, which is where
postfix will obtain its emails. The hostnames will look something like
mail.mydomain.com, smtp.mydomain.com. You incorporate the hostname
this way:
myhostname = mail.mydomain.com
exampledomain.com
Vidyavardhini’s College of Engineering & Technology
This option is the mail domain that you will be servicing, like mydomain.com
mydomaindomain.com = mydomain.com
myorigin
All emails sent from this mail server will look as though they came from the
one that you specify in this option. You can set this to $exampledomain.com.
myorigin = $exampledomain.com
Use any value that you want for this option but put a dollar sign in front of it
like this: $exampledomain.com.
mydestination
This option shows you which domains the Postfix server uses for incoming
emails to your Linux email server. You can assign values like this:
mail_spool_directory
mynetworks
This will let you arrange which servers can relay through your Postfix server.
It should only take local addresses like local mail scripts on your server. If
this isn’t the case, then spammers can piggyback on your Linux mail server.
That means your lovely shiny server will be doing the heavy lifting for some
bad guys and it will also end up getting banned. Here’s the syntax for this
option:
smtpd_banner
Vidyavardhini’s College of Engineering & Technology
This one determines what message is sent after the client connects
successfully. Consider changing the banner so it doesn’t give away any
potentially compromising information about your server.
inet_protocols
inet_protocols = ipv4
When you change any of files used to configure Linux mail server for
Postfix, you must reload the service, with this directive:
Of course, we all get distracted and typing things in can often result in
mistakes, but you can track down any misspellings that might compromise
your Linux mail server using this command:
$ postfix check
$ mailq
If that reveals that its full then you can flush the queue using this command:
$ postfix flush
Look at it again and you should see that your Linux email server queue is
clear.
$ echo "This is the body of the message" | mailx -s "Here we have a Subject"
-r "for instance <small example@mydomain.com>" -a /path/to/attachment
Vidyavardhini’s College of Engineering & Technology
someone@mydomain.com
Then check if your Linux email server can pick up external mail. If you run
into any snags, have a peek at the logs. The Red Hat log file can be found
in /var/log/maillog and for Debian versions in /var/log/mail.log, or wherever
else the rsyslogd configuration specifies. I would suggest you review the
Linux syslog server for an in-depth clarification on logs and how to set up
rsyslogd. If you run into any more difficulties, take a look at your DNS
settings and use Linux network commands to check your MX records.
Once you’ve done that, you can see how it’s configured in the
/etc/mail/spamassassin/local.cf file. SpamAssassin runs a number of scripts to
test how spammy an email is. The higher the score that the scripts deliver, the
more chances there are that it’s spam.
In the configuration file, if the parameter required_hits is 6, this tells you that
SpamAssassin will consider an email to be spam if it scores 6 or more.
:0 hbfw | /usr/bin/spamc
Then we’ll edit the Postfix configuration file /etc/postfix/main.cf and alter the
mailbox_command, thus:
mailbox_command = /usr/bin/procmail
strict_rfc821_envelopes = yes
relay_domains_reject_code = 554
unknown_address_reject_code = 554
unknown_client_reject_code = 554
unknown_hostname_reject_code = 554
unknown_local_recipient_reject_code = 554
unknown_relay_recipient_reject_code = 554
unverified_recipient_reject_code = 554
smtpd_recipient_restrictions =
reject_invalid_hostname,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
Vidyavardhini’s College of Engineering & Technology
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_rbl_client dsn.rfc-ignorant.org,
reject_rbl_client dul.dnsbl.sorbs.net,
reject_rbl_client list.dsbl.org,
reject_rbl_client sbl-xbl.spamhaus.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client dnsbl.sorbs.net,
permit
The above RBLs are the most common ones found, but there are plenty more
on the web for you to track down and try.
Dovecot Installation
Dovecot is preinstalled on the majority of Linux distributions, and there’s no
problem putting it in Red Hat too:
For Debian, a pair of packages provide the IMAP and POP3 functionality.
Here’s how to install them:
You will be prompted to create self-signed certificates for using IMAP and
POP3 over SSL/TLS. Select yes and type in the hostname of your system
when asked to do so.
Then you can run the service and activate it at start-up like this:
Vidyavardhini’s College of Engineering & Technology
Configure Dovecot
The main configuration file for Dovecot is /etc/dovecot/dovecot.conf file.
listen = *, ::
The asterisk means all ipv4 interfaces and :: means all ipv6 interfaces
mail_location = mbox:~/mail:INBOX=/var/mail/%u
Secure Dovecot
Dovecot features generic SSL certificates and key files used with
/etc/dovecot/conf.d/10-ssl.conf
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem
Vidyavardhini’s College of Engineering & Technology
If you try to connect to a dovecot server and certificates haven’t been signed,
then you’ll get a warning, but if you go to a certificate authority you can buy
one, so no worries there.
ssl_cert = </etc/letsencrypt/live/yourdomain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/yourdomain.com/privkey.pem
You’ll need to open dovecot server ports in your iptables firewall by adding
iptables rules for ports 110, 995, 143, 993, 25.
$ firewall-cmd --reload
Linux mail server (and particularly Postfix) is one of the simplest systems
you can work with.
Conclusion
Post
experiment
quiz
Vidyavardhini’s College of Engineering & Technology
Theory: The Domain Name System (DNS) is used to resolve (translate) hostnames to internet
protocol (IP) addresses and vice versa. A DNS server, also known as a nameserver, maps IP
addresses to hostnames or domain names.
Vidyavardhini’s College of Engineering & Technology
Sending a request from the DNS client to the DNS server is called a lookup request.
Getting a response from the DNS server to the DNS client is called a lookup response. The
system on which the DNS service is configured is called a DNS server. The system that
accesses the DNS server is called a DNS client.
The DNS workflow illustrates how communication happens within DNS and how it resolves
the addresses.
1. When the client searches for the domain www.example.com, the request will initially
go to the internet service provider's (ISP) resolver. It will respond to the user's request
to resolve a domain name.
2. If the IP address is not found on the resolver, the request is forwarded to a root DNS
server and later to the top-level domain (TLD) servers.
3. TLD servers store information for top-level domains, such as .com or .net.
Vidyavardhini’s College of Engineering & Technology
1. Requests are forwarded to the nameservers, which know detailed information about
domains and IP addresses.
2. Nameservers respond to the ISP's resolver, and then the resolver responds to the client
with the requested IP.
3. When the resolver doesn't know the IP, it stores the IP and its domain in a cache to
service future queries.
The BIND package provides the named service. It reads the configuration from the
/etc/named and /etc/named.conf files. Once this package is installed, you can start
configuring DNS.
Note: By default, the named.conf file includes the /var/named directory for checking zone
files. Sample zone files named. localhost and named. loopback are created during the
installation of the BIND package.
[main]
dns=none
Save the file and reload (restart) NetworkManager.
nameserver 192.168.25.132
[ Be prepared in case something goes wrong. Read An introduction to DNS
troubleshooting. ]
;; AUTHORITY SECTION:
example.com. 86400 IN NS servera.example.com.
...output truncated...
This example displays a reverse lookup, where the DNS server responds with
servera.example.com as the domain name for 192.168.25.132:
;; ANSWER SECTION:
132.25.168.192.in-addr.arpa. 86400 IN PTR servera.example.com.
;; AUTHORITY SECTION:
25.168.192.in-addr.arpa. 86400 IN NS servera.example.com.
;; ADDITIONAL SECTION:
servera.example.com. 86400 IN A 192.168.25.132
...output truncated...
Conclusion
Post
experiment
Quiz