0% found this document useful (0 votes)
21 views22 pages

Linux Basics

The document outlines an IT workshop for KTU, focusing on Linux and networking skills, with a structured lab manual for various experiments including basic commands, networking, OS installation, and shell programming. Instructors include Dr. Sunil TT, Sri Shibu V, and Navaneeth S, and the workshop will utilize virtual machines for hands-on learning. Key topics covered include file management, network analysis, Git, and web development, along with a comprehensive overview of the Linux filesystem and system administration tasks.

Uploaded by

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

Linux Basics

The document outlines an IT workshop for KTU, focusing on Linux and networking skills, with a structured lab manual for various experiments including basic commands, networking, OS installation, and shell programming. Instructors include Dr. Sunil TT, Sri Shibu V, and Navaneeth S, and the workshop will utilize virtual machines for hands-on learning. Key topics covered include file management, network analysis, Git, and web development, along with a comprehensive overview of the Linux filesystem and system administration tasks.

Uploaded by

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

IT Workshop for KTU -Lab manual outline

Instructors:
1) Dr.Sunil TT, Director , ICFOSS
2) Sri Shibu V , College of Engineering Karunagapally (Rtd)
3) Navaneeth S, Research Associate, ICFOSS

Introduction
This workshop will be conducted online. All participants will get a virtual machine installed with
Ubuntu to try out the experiments. The participants are also expected to install Ubuntu 22.04 or
later locally on their computers. The lessons/ lab plan will be available on ICFOSS moodle LMS for
later use.
The lesson plan is reorganized to suit the steep learning curve of students/ teachers. Initial lessons
will be based on an installed system. The installation of os / networking hardware will be taken up
towards the end of the workshop .

Experiment 1 Basic Unix/Linux Commands

• Familiarizing with Linux . Desktops, Basic desktop applications. Command line


• Basic commands for file and directory management
• Commands for system administration

Since most of the students are new to linux, This experiment is designed to make them students
understand the organization of he file system, system architecture and how linux is organized as a
multi user system.
The following commands should be taught -: ls, cd, mkdir, pwd, rm , rmdir ,
adduser ,passwd, cpuinfo , du, top fdisk
chmod
At the completion of this experiment students should be familiar with file system organization, how
passwords and user info is maintained, inspect system specification, manipulate files and
directories and install software from repository. The instructor should take at least 2 lab sessions
with plenty of exercises the above theme. ( Excercises will be provided) Some of the commands
like wall are no longer used and can be dropped

Experiment 2 Introduction to networking

Introduction to networking : hardware, ( demo of RJ45 connector – switch, router wireless


access points)

How internet works: IP address and net mask routing , DNS system , DHCP
The following commands should be taught: ip , route traceroute nslookup,ping ifconfig( mention
about windows equivalents)

ifconfig and traceroute are deprecated now and needs


extra package installation

Remote access: ssh , how ssh works, how ssh can be used with keys,
Introduce open sshserver and putty ( on windows)

Additional experiments : Remote desktops, rdp vnc

Experiment 3 OS Installation

It is suggested that students be introduced to installation after they are familiar with commands.
Give the virtual machines to experiment. Virtual box or proxmox environment can be setup.
(ICFOSS has a proxmox platform which can server virtual machines over internet. )

Install on virtual box and make students confident about the steps to follow.

• Install ubuntu and widows on virtual box

• Install a dual boot on a real machine

• Configure users , network

• Introduce the boot process, Major Bios settings grub UEFI

• How to trouble shoot if they fail . Introduce tools like supergrub boot cd

Experiment 4 Network Traffic Analysis

Introduce TCP IP packet structure, how ethernet works?

• Introduction to Wireshark . Capture and filter network traffic.

Introduce how layered architecture in TCP/IP and mention about http , https
• Analyze basic protocols (HTTP, TCP/IP) Inspect specific protocol packets using wireshark
Experiment 5: Shell Programming

Basics of shell scripting: Variables, loops, and conditions.


• Practical: Write a script to list files with sizes.
• Introduce commands like head tail wc for shell scripting
Automate tasks with cron. (Demo this )
• Practical: Schedule a script to run automatically.

Experiment 6 : LaTeX Basics

• : Introduction to LaTeX: Document structure and basic formatting.

Generate a PDF report with images and lists.

Experiment 7 Git and version control


Git basics (initialize repository, commits).
• Push changes to GitHub :

• Branching, merging, and resolving conflicts.

• Create and merge branches locally.


• Pull requests and collaboration.

Experiment 8:Development Environment Familiarization


• Install and configure Visual Studio Code,
• Test code snippets for Python and JavaScript.
Compare features and debug small scripts.

Experiment 9 -: Web development


Install apache2 webserver and configure. Create simple webpage . JavaScript examples
Linux filesystem
Introduction The Linux directory structure is a hierarchical system that organises files and
directories, with the root directory (/) at the top, from which all other directories branch off.
Navigating this structure effectively via the command line is crucial for managing and using a
Linux system.

1. Navigating the File System

Commands:
• pwd - Print Working Directory
• ls - List directory contents
• cd - Change directory
The command line, or terminal, is a text-based interface used to interact with the operating system.
It provides powerful tools for navigating and managing the Linux file system. Here are some
essential commands:

• ls: This command lists the contents of a directory.


• To list the contents of the current directory, simply use ls.


• To move to a specific directory, use cd <directory_path>. For example,


cd /home/sunil
• To move up one level in the directory hierarchy, use cd ...
• To return to the user's home directory, use cd with no arguments.
• pwd: This command prints the current working directory. It is useful when you are unsure of
your current location in the directory tree.
• tree: This command displays the directory structure in a tree-like format.
• To install tree on Debian or Ubuntu, use: sudo apt install tree.

• To display the entire file system tree starting from the root directory, use tree /.
• To display only the first level of subdirectories, use tree -L 1 /.
• 2. Managing Files and Directories
• Commands:
• cp - Copy files or directories
• mv - Move or rename files and directories
• rm - Remove files or directories
• mkdir - Create a directory
• rmdir - Remove an empty directory

mkdir : create a folder


rmdir delete folder

cat
Create a file named myfile.txt in itws folder using editor.
You can view contents using cat command
rm : delete file

Key Directories in the Linux File System


Here’s an explanation of the most important directories found directly under the root directory /:
• /bin: This directory contains essential binaries, or executable programs, that are needed for
basic system operation. For example, the ls command is often located in /bin. It can
sometimes be a symbolic link to /usr/bin.

• /boot: This directory contains files required for booting the system. It is crucial not to
modify or delete any files in this directory, as doing so could prevent the system from
starting.

• /dev: This directory contains device files, which represent hardware devices connected to
the system. These files are often generated automatically when the system boots or when a
new device is connected. For example, when you plug in a USB drive, a device entry will
appear in /dev.

• /etc: This directory contains system-wide configuration files. The name /etc historically
meant "et cetera" as a place to put system files, but now it can be understood as "Everything
to Configure". It contains files that control system settings, such as users, passwords,
network settings, and disk mount points. It is best not to modify files in /etc unless you
fully understand the changes you are making.

• /home: This directory contains the personal directories of each user on the system. For
instance, if your username is "sunil," your personal files would be stored in /home/sunil.
• /lib: This directory contains libraries, or shared code files, used by applications. These
libraries contain code that helps applications draw windows, control hardware, and write
files. Like /bin, there are often libraries in /usr/lib, and these may be linked to each
other. The /lib directory also contains essential kernel modules.

• /media: This directory is used for automatically mounting external storage devices, such
as USB drives, when they are inserted and accessed.

• /mnt: This directory is used for manually mounting storage devices or partitions. It is less
commonly used nowadays.

• /opt: This directory is often used for software that is compiled (built from source code)
and not installed from your distribution's software repositories. Software will be located in
/opt/bin and libraries in /opt/lib. Another location for such software is
/usr/local, with /usr/local/bin and /usr/local/lib directories.

• /proc: This is a virtual directory that contains information about the system, including the
CPU and running kernel. The files and directories in /proc are generated dynamically
when the computer starts or while the system is running.

• /root: This is the home directory of the superuser (also known as the "Administrator"). It
is a separate home directory from other users. It is not meant to be modified, so keep
personal files in your own directories.
• /run: This directory is used by system processes to store temporary data. Like /boot and
/root, it's best not to touch this directory.
• /sbin: This directory contains system binaries, or executable programs, that are used by
the superuser (system administrator) for system maintenance. These commands can be used
with the sudo command, which grants temporary superuser privileges. For example, tools
to install, delete, and format software and hardware can be found here.
• /srv: This directory contains data for servers. If you are running a web server, your website
files would go in /srv/http or /srv/www. If you are running an FTP server, your files
would go into /srv/ftp.
• /sys: This is another virtual directory that contains information about devices connected to
your computer. You can sometimes manipulate devices by modifying files in /sys, but this
should only be done by advanced users. Avoid modifying this directory unless you know
what you are doing.
• /tmp: This directory contains temporary files. Unlike many other directories, users can
create, modify, and delete files in /tmp without requiring superuser privileges.
• /usr: This directory was originally where users' home directories were kept, but now it
contains a mix of directories, applications, libraries, documentation, and other shared
resources. It contains /usr/bin, /usr/sbin, and /usr/lib directories which may
mirror those found directly under the / root directory, but /usr subdirectories usually
contain user-installed applications, whereas those found directly under the root contain core
system functionality.
• /var: This directory contains variable data that changes frequently. For example, log files
are stored in the /var/log subdirectory. It also includes spools for tasks like print jobs and
email.
Many of the directories mentioned above have their own subdirectories with their
own functions and purpose. To explore them use the cd command.

• For example, cd /usr/share will move you to the /usr/share directory.


• If you then want to know where you are use pwd to see the present working directory, which
will be /usr/share.
• If you want to list the contents of /usr/share use ls.
• To get an overview of the directory tree from your present location, you can use the tree
command.
.

Command Line System Administration Tutorial


System administration often involves managing and configuring a system through a command-line
interface (CLI). Below is a basic tutorial covering common tasks that a system administrator may
need to perform. This tutorial uses Linux/Unix-based systems as the examples.
1. User Management
Commands:
• useradd - Add a new user
• usermod - Modify a user
• userdel - Delete a user
• passwd - Change user password

Example:
# Add a new user called 'john'
sudo useradd john

# Add a user to a group


sudo usermod -aG sudo john

# Change the user's password


sudo passwd john

# Delete a user and their home directory


sudo userdel -r john

2. Process Management
Commands:
• ps - View current running processes
• top - View processes in real-time
• kill - Terminate a process
• htop - Interactive process viewer (better than top)

Example:
# Show all running processes
ps aux

# Real-time process viewer


top

# Kill a process by PID (replace PID with the actual process ID)
kill 1234

# Use htop for an interactive process viewer


sudo apt install htop
htop

3. Package Management (Debian-based systems)


Commands:
• apt-get - Install, upgrade, and remove packages
• apt-cache - Search for packages
• dpkg - Manage Debian packages
Example:
# Update package list
sudo apt update

# Install a package
sudo apt install nginx

# Upgrade installed packages


sudo apt upgrade

# Remove a package
sudo apt remove nginx

# Search for a package


apt-cache search vim

# Show installed packages


dpkg -l

4. Disk Usage and Management


Commands:
• df - Display disk space usage
• du - Display file or directory space usage
• fdisk - Partition table manipulator
• mount/umount - Mount and unmount filesystems

Example:
# Show disk space usage
df -h

# Show space used by files and directories


du -sh /home/user/

# List partitions
sudo fdisk -l

# Mount a filesystem
sudo mount /dev/sda1 /mnt

# Unmount a filesystem
sudo umount /mnt

5. Networking
Commands:
• ifconfig or ip - Display or configure network interfaces
• ping - Test network connectivity
• netstat - Network statistics
• ss - Socket statistics (newer tool than netstat)
Example:
# Display network interfaces
ifconfig
# Or using ip
ip addr show

# Ping a remote server to check connectivity


ping google.com

# Show network connections and listening ports


netstat -tuln

# Use ss for more detailed network stats


ss -tuln

6. System Logs and Monitoring


Commands:
• dmesg - Display kernel-related messages
• journalctl - View system logs (for systems using systemd)
• tail - Display last part of a file (useful for logs)

Example:
# View kernel messages
dmesg | less

# View the system log (for systems with systemd)


sudo journalctl -xe

# View the last 10 lines of a log file


tail /var/log/syslog

# Monitor logs in real time


tail -f /var/log/syslog`

7 Backup and Recovery


Commands:
• tar - Archive and compress files
• rsync - Sync files between locations

Example:
# Create a tar archive of a directory
tar -czvf backup.tar.gz /home/user/

# Extract a tar archive


tar -xzvf backup.tar.gz

# Sync files from one directory to another


rsync -av /home/user/ /mnt/backup/
The /etc directory is a critical component of the Linux filesystem, containing configuration files
that govern the behavior of the operating system, applications, and services. Modifications to these
files should be handled carefully, as errors can disrupt system functionality.
Here’s an overview of some key files and subdirectories in /etc:

1. Essential System Configuration Files


• /etc/passwd
• Contains user account information.
• Each line represents a user with fields like username, user ID (UID), group ID (GID),
home directory, and shell.
• Example:
root:x:0:0:root:/root:/bin/bash

• Passwords are typically stored as hashes in /etc/shadow for security.


• /etc/shadow
• Stores hashed passwords and additional password-related settings (e.g., expiration
policies).
• Restricted access to root for security reasons.
• /etc/group
• Defines groups on the system and their members.
• Example:
sudo:x:27:user1,user2

• /etc/fstab
• Configuration file for mounting file systems automatically at boot.
• Specifies details like file system type, mount point, and options.
• Example:
UUID=abc123 / ext4 defaults 0 1

• /etc/hosts
• Maps hostnames to IP addresses for local name resolution.
• Example:
127.0.0.1 localhost

• /etc/resolv.conf
• Contains DNS server information for domain name resolution.
• Example:
nameserver 8.8.8.8

2. Boot and Initialization


• /etc/inittab (deprecated on some modern systems)

• Defines system runlevels and initialization scripts.


• /etc/systemd/
• Configuration for systemd, the modern init system.
• Includes unit files for services, targets, and timers.
• /etc/init.d/
• Scripts for starting/stopping services in older systems using SysVinit.

3. Networking Configuration
• /etc/network/interfaces (Debian-based systems)

• Network interface configurations.


• Example:
auto eth0
iface eth0 inet dhcp

• /etc/sysconfig/network-scripts/ (Red Hat-based systems)

• Contains configuration scripts for network interfaces.


• /etc/hosts.allow and /etc/hosts.deny

• Used by tcp_wrappers to control access to services.

4. Application and Service Configurations


• /etc/ssh/
• Contains SSH server configuration files like sshd_config.
• Example setting:
PermitRootLogin no

• /etc/httpd/ or /etc/apache2/

• Configuration for Apache web server.


• /etc/nginx/
• Configuration for NGINX web server.
• /etc/mysql/ or /etc/mariadb/
• Configuration for MySQL or MariaDB databases.

5. Security
• /etc/sudoers
• Defines user privileges for running commands as root or other users.
• Edited using visudo to avoid syntax errors.
• Example:
user1 ALL=(ALL) NOPASSWD:ALL

• /etc/pam.d/
• Pluggable Authentication Module (PAM) configurations for authentication policies.
• /etc/selinux/
• Configuration for SELinux, a mandatory access control system.

6. System Services
• /etc/crontab
• System-wide schedule for cron jobs.
• Example:
0 5 * * * root /usr/bin/backup.sh

• /etc/rsyslog.conf
• Configuration for system logging via rsyslog.
• /etc/udev/
• Rules for dynamic device management.

7. Package Management
• /etc/apt/ (Debian-based systems)

• Configuration for apt, including sources (sources.list) and preferences.


• /etc/yum.repos.d/ or /etc/dnf/ (Red Hat-based systems)

• Repository configurations for package management.

8. User Environment
• /etc/profile
• System-wide environment variables and startup scripts for all users.
• /etc/bashrc or /etc/bash.bashrc
• Global configuration for Bash shell.

9. Backups and Precautions


• Backup critical files regularly, especially those like:
• /etc/passwd, /etc/shadow, /etc/fstab, /etc/hosts,
/etc/sudoers.
• Use tools like etckeeper to version-control /etc.
• Always test changes in a non-production environment if possible.
By understanding the purpose and structure of these critical files, you can efficiently manage and
troubleshoot Linux systems.

Shell Scripting Tutorial for Beginners


Shell scripting is a powerful way to automate tasks in Linux. A shell script is a file containing a
series of commands that the shell executes sequentially. This tutorial introduces the basics of shell
scripting.

1. Getting Started with Shell Scripting


Step 1.1: Create a Shell Script
1. Open a terminal.
2. Use a text editor (e.g., nano, vim, or gedit) to create a file:
nano script.sh

3. Add the following lines to the file:


#!/bin/bash
echo "Hello, World!"

4. Save the file and exit the editor.

Step 1.2: Make the Script Executable


1. Change the file's permissions to make it executable:
chmod +x script.sh

2. Run the script:


./script.sh
2. Basic Components of a Shell Script
Comments
• Comments start with # and are ignored by the shell:
# This is a comment
echo "This will be executed"

Variables
• Define variables without spaces around =:
name="Linux"
echo "Welcome to $name!"

User Input
• Read input from the user:
echo "Enter your name:"
read name
echo "Hello, $name!"

Conditional Statements
• Use if statements for decision-making:
echo "Enter a number:"
read number
if [ $number -gt 10 ]; then
echo "The number is greater than 10."
else
echo "The number is 10 or less."
fi

Loops
• Use loops to repeat tasks:
• For Loop:
for i in 1 2 3 4 5; do
echo "Number: $i"
done

• While Loop:
count=1
while [ $count -le 5 ]; do
echo "Count: $count"
((count++))
done
3. Working with Files
Check if a File Exists
file="test.txt"
if [ -e $file ]; then
echo "File exists."
else
echo "File does not exist."
fi

Read a File Line by Line


while read line; do
echo $line
done < test.txt

Write Output to a File


echo "This is a line of text" > output.txt

4. Functions in Shell Scripts


Define reusable functions:
greet() {
echo "Hello, $1!"
}
greet "Alice"
greet "Bob"

5. Debugging a Shell Script


Run a Script in Debug Mode
Use -x to debug a script:
bash -x script.sh

6. Example Scripts
Example 1: Backup Files
#!/bin/bash
backup_dir="backup_$(date +%Y%m%d)"
mkdir -p $backup_dir
cp *.txt $backup_dir
echo "Backup completed. Files copied to $backup_dir"

Example 2: Disk Usage Alert


#!/bin/bash
threshold=80
usage=$(df / | grep / | awk '{print $5}' | sed 's/%//')

if [ $usage -gt $threshold ]; then


echo "Warning: Disk usage is above $threshold% ($usage%)"
else
echo "Disk usage is under control ($usage%)"
fi

7. Best Practices
• Use Comments: Document your script for clarity.
• Error Handling: Handle errors gracefully using set-e or conditional checks.
• Permissions: Use chmod to control access to scripts.
• Modular Code: Use functions for reusable code blocks.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy