0% found this document useful (0 votes)
7 views

SP-Lab7

The document outlines a lab exercise for the System Programming course at the University of Engineering and Technology, Taxila, focusing on setting up and managing a DHCP server, SSH, and Telnet in a Linux environment. It includes objectives, installation instructions, user management commands, and practical lab tasks for students to complete. Additionally, it provides links to video tutorials for further assistance.

Uploaded by

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

SP-Lab7

The document outlines a lab exercise for the System Programming course at the University of Engineering and Technology, Taxila, focusing on setting up and managing a DHCP server, SSH, and Telnet in a Linux environment. It includes objectives, installation instructions, user management commands, and practical lab tasks for students to complete. Additionally, it provides links to video tutorials for further assistance.

Uploaded by

Hafsa Rafique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Lab # 07
System Programming Lab

Course Instructor: Dr. Adnan Mustafa

Date: 13/02/2025

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

DHCP SERVER
In Linux, "DHCP" stands for "Dynamic Host Configuration Protocol," which is a network
protocol that automatically assigns IP addresses and other network configuration details to
devices when they connect to a network, eliminating the need to manually configure each
device with these settings; essentially, a Linux system can act as a DHCP server to manage IP
address allocation on a network.

CLO - Describe and implement the protocols (such as TCP and IP) and interfaces (such
as sockets) used for secured communication among different computers

Objectives:
 Installation of DHCP Server.
 Selection of LAN Card.
 Configuration File.
 Specification of IP-Range.
 Services.
 Verification of working on Client’s PC.
 User Management in LINUX.
 Installation & Configuration of SSH Server.
 Installation & Configuration of TELNET Server.
 Enabling of TELNET Feature in Windows OS.
 Registration of Ports in Firewall.
 Remotely access of Server via SSH &TELNET from Windows OS.
Dynamic Host Configuration Protocol (DHCP) is used to assign IP addresses and other
stuff like gateway and DNS details automatically to the clients. we need a DHCP server
configured for offering ip address to the clients when it is required Installation:
Like any other package we need to install dhcp with yum command.

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Now open /etc/sysconfig/dhcpd file and add the preferred interface name to DHCPDARGS
variable as below.

Now edit the configuration file /etc/dhcp/dhcpd.conf file with following information

Restart your service and go to client and make following changes.

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

At command enter command ipconfig /release

And finally ipconfig /renew

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Link1: https://www.youtube.com/watch?v=_AKIVT2mzMY
Link2: https://www.youtube.com/watch?v=TTohPxCpYTQ
Link3: https://www.youtube.com/watch?v=_3RsXOvNh_8

INTRODUCTION TO USERS

whoami:
The Whoami command will tell your username.

who:
The who command will give you information about who is logged on the system.

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

who am i:
With who am i the who command will display only the line pointing to your current session.

w:
The w command shows you who is logged on and what they are doing.

id:
The id command will give you your user id, primary group id, and a list of the groups that
you belong to.

su to another user:
The su command allows a user to run a shell as another user

su to root:
you can switch to root if you know root password.

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

su as root:
You need to know the password of the user you want to substitute to, unless your are
logged in as root. The root user can become any existing user without knowing that user's
password.

su - $username:
By default, the su command maintains the same shell environment. To become another
user and also get the target user's environment, issue the su - command followed by the
target username.

su - :
When no username is provided to su or su -, the command will assume root is the target.

run a program as another user:


The sudo program allows a user to start a program with the credentials of another user.
Before this works, the system administrator has to set up the /etc/sudoers file. This can
be useful to delegate administrative tasks to another user (without giving the root
password).

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

The screenshot below shows the usage of sudo. User fahad received the right to run
useradd with the credentials of root. This allows fahad to create new users on the system
without becoming root and without knowing the root password

sudo su -:
On some Linux systems like Ubuntu and Xubuntu, the root user does not have a
password set. This means that it is not possible to login as root (extra security)
The user can type sudo su - and become root without having to
enter the root password.

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

USER MANAGEMENT

User management on Linux can be done in three complimentary ways. You can use the
graphical tools provided by your distribution. These tools have a look and feel that depends
on the distribution. If you are a novice Linux user on your home system, then use the
graphical tool that is provided by your distribution. This will make sure that you do not run
into problems.
Another option is to use command line tools like useradd, usermod, gpasswd, passwd and
others. Server administrators are likely to use these tools, since they are familiar and very
similar across many different distributions. This chapter will focus on these command line
tools.
A third and rather extremist way is to edit the local configuration files directly using vi (or
vipw/vigr). Do not attempt this as a novice on production systems!.

/etc/passwd:
/etc/passwd is the local user database on Linux system.

root:
The root user also called the superuser is the most powerful account on your Linux system.
This user can do almost anything, including the creation of other users. The root user always
has userid 0 (regardless of the name of the account).

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

useradd:
You can add users with the useradd command. The example below shows how to add a user
named yanina (last parameter) and at the same time forcing the creation of the home
directory (-m), setting the name of the home directory (-d), and setting a description (-c).

/etc/default/useradd:
Both Red Hat Enterprise Linux and Debian/Ubuntu have a file called /etc/default/useradd
that contains some default user options. Besides using cat to display this file, you can also
use useradd -D.

userdel:
You can delete the user yanina with userdel. The -r option of userdel will also remove the
home directory

usermod:

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

You can modify the properties of a user with the usermod command. This example uses
usermod to change the description of the user harry

/etc/skel/:
When using useradd the -m option, the /etc/skel/ directory is copied to the newly created
home directory. The /etc/skel/ directory contains some (usually hidden) files that contain
profile settings and default values for applications. In this way /etc/skel/ serves as a default
home directory and as a default user profile.

deleting home directories:


user -r option with userdel command to remove user along with home directory.

login shell:
The /etc/passwd file specifies the login shell for the user.In the screenshot below you can
see that user yanina will log in with /bin/bash shell.

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

You can use the usermod command to change the shell for a user.

chsh:
Users can change their login shell with the chsh command. First, user fahad obtains a list of
available shells (he could also have done a cat /etc/shells) and then changes his login shell to
the /bin/sh shell.

Link: https://www.youtube.com/watch?v=NbtBDv-gcSA
Link2: https://www.youtube.com/watch?v=Db-vFJajhAU

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

SSH
Secure Shell (SSH) is a Linux command and protocol that allows secure communication
between two devices on a network. It's used to remotely log into a machine, execute commands,
and transfer files.

Installation:
You need to install following two packages for ssh
• openssh-server
• openssh-clients
Install both packages using yum command

Start service sshd

Add port to firewall

Open configuration file with /etc/ssh/sshd_config and uncomment port 22

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Also set PermitRootLogin to Yes

Restart service

Client Setting:
Download and install putty software on your client computer

Now enter your server ip address and port 22

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Link: https://www.youtube.com/watch?v=T6BUD-U5IzM

https://www.youtube.com/watch?v=R4xR45VeAKA

TELNET
In Linux, "Telnet" is a network protocol that allows users to connect to a remote computer
system and interact with it through a command line interface, essentially providing a way to
remotely manage a machine by sending text commands over a network, typically using port
23; however, it is considered insecure as it transmits data in plain text without encryption,
making it largely outdated in favor of more secure options like SSH.

Installation:
Install following packages on centos using yum command

• telnet
• telnet-server

Now edit the /etc/xinetd.d/telnet file and set disable=no

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Make sure that service xinetd is running

As telnet port is 23 so we will add port 23 to firewall

Now add new user as by default root user has no permission to access telnet

Now on the client side enable telnet feature from control panel

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Now open command prompt and access telnet with telnet 13.23.1.1 (Note :13.23.1.1 is my
server ip) and give your credentials

Link https://www.youtube.com/watch?v=Lf5d21QhQQI
Link2: https://www.youtube.com/watch?v=I8bhRBvCs8M

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

System Programming 8th Semester-2k21-CP UET Taxila


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

Computer ENGINEERING DEPARTMENT

Lab Tasks:
1. Run a command that displays only your currently logged on user name.
2. Display a list of all logged on users.
3. Display a list of all logged on users including the command they are running at this
very moment.
4. Display your user name and your unique user identification (userid).
5. Use su to switch to another user account (unless you are root, you will need the
password of the other account). And get back to the previous account. 6. Now use su -
to switch to another user and notice the difference.
7. Create a user account named serena, including a home directory and a description
(or comment) that reads Serena Williams. Do all this in one single command.
8. Create a user named venus, including home directory, bash shell, a description that
reads Venus Williams all in one single command.
9. Verify that both users have correct entries in /etc/passwd, /etc/shadow and
/etc/group.
10. Verify that their home directory was created.
11. Create a user named einstime with /bin/date as his default logon shell.
12. What happens when you log on with the einstime user ? Can you think of a useful
real world example for changing a user's login shell to an application ?
13. Create a file named welcome.txt and make sure every new user will see this file in
their home directory.
14. Verify this setup by creating (and deleting) a test user account.
15. Change the default login shell for the serena user to /bin/bash. Verify before and
after you make this change.
16. Use telnet and ssh to access linux from client computer.

System Programming 8th Semester-2k21-CP UET Taxila

You might also like