My Linux Project Command Line Revealed

IritT
21 min readMay 10, 2024

--

Linux, the open-source operating system, has become a powerful and versatile platform for countless applications, from web servers to scientific computing and everything in between. Through this journey, I acquired practical skills and a deeper understanding of the principles that govern Linux’s operation.

Now, let’s fire up our terminals and dive into the exciting world of Linux!

Part 1: Basic Commands and Directory Management

This part will explore how to understand basic Linux commands and guide you through fundamental commands for managing files and directories in the Linux environment.

1. Switching Users: su

Objective: Log into su user.

# su

· su — switch to the superuser (root) which allows for broader system management capabilities.

· su user_name — switch to user

Use this command when you need administrative privileges to perform tasks that are restricted to regular users.

1. Navigating Directories: cd

Objective: navigate to the home/desktop directory

# cd /home/iritp/Desktop

Master how to change directories to access different parts of the filesystem.

· cd — changes the directory to the user’s home directory.

· cd ~ — Go to the home directory (user’s home directory).

· cd / — changes the directory to root directory of the file system, which is the highest level of the directory structure.

· cd /path/to/directory — changes the directory to a specific location in the filesystem

· cd .. — moves the directory context up one level.

· cd . — refers to the current directory itself.

These commands are fundamental for moving through the directory structure of your system, whether you’re accessing files, running scripts, or managing folders.

2. Creating Directories and Files: mkdir and touch

Objective: Create 3 new directories and 3 new files using a single command.mkdir dir1 — Create directories.

# mkdir dir1 dir2 dir3 && touch file1.txt file2.txt file3.txt

· touch file1.txt — Create multiple files.

· mkdir dir1 dir2 dir3 — Create multiple directories.

· touch file1.txt file2.txt file3.txt — Create multiple files.

These commands are essential for organizing your filesystem. You might need to create directories for new projects and files for logs or scripts.

3. Listing Directory Contents: ls

Objective: Display the files and directories within the current directory.

# ls
# ls -a

· ls — List visible files and folders

· ls -a — List all files, including hidden ones

This command is useful for verifying the results of file creation and deletion, or just to check the contents of a directory.

4. Moving Files: mv

Objective: Move the files to one of the directories you created and Navigate to the directory containing the files and move the files to another directory.

# mv file1.txt file2.txt file3.txt dir1/
# cd /home/iritp/Desktop/dir1 or # cd dir1
# mv file1.txt file2.txt file3.txt ../dir2/
# cd /home/iritp/Desktop/dir2

· mv file1.txt dir1/ — move a file to a directory

· mv oldname.txt newname.txt — rename a file

Moving and renaming files are common tasks, whether organizing files or updating filenames to reflect their content or version.

5. Deleting Files and Directories: rm

Objective: Delete the files from the directory.

# rm file{1..3}.txt

· rm file1.txt — Delete a file.

· rm -r dir1 — Delete a directory and its contents.

Regular maintenance of your filesystem might require you to delete old or unnecessary files and directories.

6. Displaying Current Directory Path: pwd

Objective: Check the path of the current directory.

# pwd

This command Helps confirm your current location within the filesystem, useful, especially after several navigation commands.

7. checking what we know so far.

Objective: Navigate to the Desktop directory and display the files and folders it contains, also if any hidden files in this directory, how can we display them?

# cd ..
# ls
# ls -a or ls - all

8. Checking Logged-in User: whoami or id -un

Objective: Check which user you are logged in as, in two ways.

# whoami
# id -un

u (UID) displays only the user ID of the current user.

n (name) used white u to translate the user ID to the user’s name

The difference lies in the base command id, which can be used for both user and group identity information.

It is important for security and user management, especially when multiple users have access to the same system.

9. Change the user password: passwd

Objective: Change the user password.

# passwd

This command is essential for user security management, the `passwd` command allows for password changes, helping maintain secure and updated credentials.

10. clear the terminal screen: clear

Objective: Clear the terminal from the output.

# clear or Ctrl+L

This tool is essential for managing terminal readability by clearing the screen of previous outputs.

11. A user-friendly text editor: nano

Objective: Create a file using NANO and write your favorite operating system’s name. In addition, find a way to display the current operating system type and add the output to the file

# nano myfavos.txt

In nano:

Ctrl+o save the change

Enter

Ctrl+x to exit nano

Whether you’re writing scripts, editing configuration files, or taking notes, nano provides a straightforward interface for text editing.

· display the current operating system type and add the output to the file

# uname -o
# uname -o >> myfavos.txt

The uname command provides information about the specific operating system running on the system.

12. Display the contents of a file: cat

Objective: Display the contents of files.

# cat myfavos.txt

· cat file1.txt — Display the contents of a File.

· cat file1.txt file2.txt — Display the contents of multiple Files

fundamental command-line tool that serves related to viewing, concatenating, and manipulating files.

13. Hidden files

· Hidden files: start with a dot (.).

Objective: To check what I learned about the basics of file and directory management in Linux:

Create three hidden files.

Execute a command that will display these files.

List all files in your home directory, including hidden ones.

Delete the hidden files created.

# touch .hidden1 .hidden2 .hidden3
# ls -a
# rm .hidden1 .hidden2 .hidden3

Is used mainly for storing configuration settings and system information. They are not listed in standard directory views to prevent accidental modifications, helping maintain system integrity and user settings privacy.

Part 2: Advanced Search Commands in Linux

This part will explore how a variety of powerful search commands enhance your ability to manage large datasets and complex directory structures in Linux.

1. Creating and Listing Files in System Directories

Objective: Create files in every system directory and display the paths of these files.

# find /usr/ -type d -exec touch {}/testfile.txt \; -exec echo {} \;

This command uses find to locate every directory (-type d) within /usr, creates a testfile.txt file in each using touch, and then prints the path of each directory. This is useful for testing permissions and ensuring that the files can be created in the required directories.

2. Finding Files by Name Pattern

Objective: Navigate to the root directory and display all files that start with 3 digits.

# cd / && find / -type f -name "[0–9][0–9][0–9]*"

This command first ensures you are in the root directory (cd /), then searches for files (-type f) whose names start with three numbers (-name “[0–9][0–9][0–9]*”). It’s useful for locating system files or logs that are typically numbered.

3. Locating Files with Numeric Prefixes

Objective: Search for all files in the system that start with 5 numbers.

# find / -type f -name "[0–9][0–9][0–9][0–9][0–9]*"

Extends the basic search to find files that start with a sequence of five digits, which can help identify specific logs or batch files that follow a numeric naming convention.

4. Finding Files by Specific Name Start

Objective: Search for all files in the system that start with the word “bash”

# find / -type f -name "bash*"

Useful for finding scripts or configurations related to bash, this command scans the entire system for files beginning with “bash,” aiding in quick script audits or configuration checks.

5. Identifying Small Directories

Objective: Search for all directories smaller than 4MB.

# du -sm /* 2>/dev/null | awk '$1 < 4' | cut -f2-

6. Searching for Small Files

Objective: Search for all files smaller than 3MB.

# find / -type f -size -3M

This command helps locating smaller files which might be logs, configurations, or temporary files, facilitating system cleanup or analysis.

Part 3: User and Group Management

This part will explore how to manage users and groups. ensuring users have appropriate access to resources

1. Creating Users

Objective: Create a user in two different ways.

# adduser user_1
# useradd user_2

adduser is more interactive and user-friendly, guiding you through each step, while useradd provides a faster, non-interactive method, useful for scripting.

2. Setting User Passwords

Objective: Set a password for the user you created.

# passwd user_2 

Passwords are crucial for user authentication; this command allows you to secure user accounts immediately upon creation.

3. Creating a New Group

Objective: Create a new group.

# groupadd new_group
# grep new_group /etc/group
(Verify the Group Creation)

Groups are used to manage permissions for multiple users efficiently. This command is essential for setting up structured access controls.

4. Modifying User Group Membership

Objective: Move the user you created in item 1 to the new group.

# usermod -a -G new_group user_1
# usermod -g new_group user_2

Managing user group memberships is key to controlling access to files and directories. The -a -G option adds the group without removing existing groups, while -g changes the primary group for the user.

5. Displaying User Groups

Objective: Display the new user in the group.

# groups user_1
# groups user_2

This command helps verify group memberships, ensuring that users have the correct access privileges.

6. Locating User Directories

Objective: Where are all the user directories in the system located?

# echo "User directories are typically located in: /home"
😊

The /home directory is the default location for user-specific directories, each named after the user’s login.

7. Switching Users

Objective: Switch to another user.

# su user_1
# whoami

This command is used to perform tasks with the permissions of another user, which is crucial for testing and management.

8. Directory Creation as a Different User

Objective: Create a directory with the new user.

# cd ~
(Navigate to the home directory of the current user)
# mkdir newdir
(Create a new directory named newdir)
# ls
(List the contents to verify creation)

Demonstrates how to manage files and directories under different user contexts, an essential skill for user-specific data management.

9. Fundamental Actions for Directory Management

Objective: What action must you perform to create a new directory?

navigating to the home directory of the current user.

cd ~

going to the home directory of the current user is essential for file and directory management within the user’s personal space.

10. Advanced User Creation and Privilege Assignment

Objective: Switch to the ROOT user, create a new user, and add him to the SUDOERS group with only one command.

# su
# useradd -m user_3 && usermod -aG sudo user_3
# id user_3

This is a crucial operation for setting up users with administrative privileges, allowing them to execute commands with elevated rights.

10. Delete User and Group as a Different User

Objective: Delete User and Group as the switched user.

# grep 'user_2' /etc/group
(Check if the User Exists in the Group File)
# ps -u user_2
(Check Running Processes for the User)
# userdel -r user_2
(Delete the User)
# groupdel user_2
(is not the primary group of any user but still exists, you can manually remove it)
# grep 'user_2' /etc/passwd
(Verify User Deletion from the User Account File)
# grep 'user_2' /etc/group
(Verify User Deletion from the Group File)

· Check for Any Remaining User Files

# find / -user user_2 2>/dev/null

Always ensure you have backups of important data before deleting user accounts, especially in a multi-user environment. This will help avoid accidental loss of critical information.

Part 4: Managing Permissions

This part will explore how to set the correct setting of permissions. It will cover how to create files, set permissions, and manage file ownership, equipping appropriate access control.

1. Creating Files and Setting Write Permissions

Objective: Create two new files in one of the directories that were created in part 1 and allow only write permissions for all files in that directory.

# find /home/iritp -type d -name "dir1" 2>/dev/null
(Find the directory where files will be created)
# cd /home/iritp/Desktop/dir1
(Navigate to the directory that was created in part 1)
# touch file1.txt file2.txt
(Create two new files)
# ls -l
(Check the files are created with default permissions)
# chmod a=w *
(Set write-only permissions for all files in the directory)
# ls -l
(Verify permissions change)

This demonstrates how to restrict file permissions to write-only for all users (a=w). It’s useful where files need to be modified but not readable, such as when handling sensitive like write-once data logs.

2. Setting Full Permissions for a File

Objective: For one file of your choice in the directory, give all possible permissions.

(read, write, execute).
# chmod 777 file1.txt
Set full permissions
# ls -l
(Verify the permissions have been set)

The chmod 777 command makes a file readable, writable, and executable by all users. This level of access is typically used for files that need to be universally accessible within the system, such as shared scripts or data files in a development environment.

3. Changing File Ownership

Objective: Choose one file and change its owner.

# chown user_1 file1.txt
(change file owner)
# ls -l file1.txt
(Verify the change in ownership)

This command is crucial when files are managed or maintained by a different user, such as when responsibilities are transferred between team members or configuring files for specific services that run under dedicated user accounts.

Part 5: Network Configuration and Address Settings

This part will explore how to use the ifconfig command to view and modify network interface settings, and how to handle IP addressing to ensure correct network setup.

1. Viewing Network Interface Configuration

Objective: Execute the ifconfig command.

# ifconfig

ifconfig displays the current configuration for all active network interfaces, including IP addresses, subnet masks, and interface status.

2. Formatting Output in Uppercase

Objective: Change the output of the command to uppercase letters.

# ifconfig | tr '[:lower:]' '[:upper:]'
Or
# ifconfig | awk '{print toupper($0)}'

Transforming output to uppercase can make certain aspects stand out more clearly.

3. Filtering for IP and Subnet Mask

Objective: Filter the command to display only the IP and SUBNET MASK.

# ifconfig | grep -E 'inet ' | awk '{print $2, $4}'

This command is essential for quickly checking the IP configuration of a system without sifting through unnecessary details.

4. Saving Network Settings to a File

Objective: Write the filtered IP and subnet mask information to a file named “ip.log.”

# ifconfig | grep -E 'inet ' | awk '{print $2, $4}' > ip.log
# cat ip.log
(Verify the contents of the file)

Saving configuration details to a file can be useful for audits, documentation, or as a backup before making changes useful for record-keeping or scripting uses.

5. Appending Additional Information to a File

Objective: Add the following to the ip.log file: whoami, last, and hostname.

# (whoami; last; hostname) >> ip.log
# cat ip.log
(Display the updated file contents)
# ls -lh ip.log && tail ip.log
(Check file size and display the last entries)

This enriches the log file with additional context about the user and system, which can be helpful for comprehensive system monitoring or troubleshooting.

6. Setting a Static IP Address

Objective: Configure a network interface with a static IP address using a text editor or a network manager tool.

# nano /etc/network/interfaces
(Using nano to edit network configuration files)

Add

auto eth0

iface eth0 inet static

address 10.0.0.100

(Save and exit from nano using CTRL+O, Enter, and CTRL+X)

# cat /etc/network/interfaces
(Display the updated file contents)
# reboot
(Reboot to apply changes)

After reboot displays the current configuration setting with the new static IP Address

# ifconfig

Setting a static IP address is useful for ensuring reliable network services, simplifying network management, enabling consistent remote access, and maintaining stable DNS configurations. It helps avoid issues with DHCP and is essential for servers hosting critical services that require constant connectivity.

Part 6: Remote Control and Telnet Services

This part will explore how to understand and manage remote access through Telnet. It will guide you through installing, configuring, and testing Telnet services.

1. Installing Telnet

Objective: Install telnet in the operating system.

# apt-get update && apt-get upgrade -y
(Update and Upgrade to the latest versions of package lists)
# apt-get install telnetd xinetd && apt-get install telnet
(Install Telnet server and client)

“Updating and upgrading your system enhances security and ensures compatibility before installing new software. The Telnet client (telnet) and server (telnetd) facilitate remote connections, enabling command execution on servers as if physically present.

2. Restarting the Telnet Service

Objective: Restart the service.

# systemctl restart xinetd
(telnetd is being managed by xinetd, you will restart xinetd since
it's the service supervising telnetd)

Restarting the service ensures that any changes made to the configuration files or updates installed are applied correctly.

3. Checking the Service Status

Objective: Check the status of the service.

# systemctl status xinetd
(Check the status of the Telnet service)
# systemctl restart xinetd
(if it not active Restart the service again if changes were made)
# systemctl status xinetd
(Check the status of the Telnet service)

Regularly checking the status of critical services like Telnet ensures they are operating as expected. Viewing and editing the configuration file helps customize how the service functions.

Telnet is working on port 23 to see if the machine can accept connections via Telnet on port 23 (in the machine we want to listen from)


# nc -lvnp 23

To listen on port 23 is a method to check for incoming Telnet connections, as port 23 is traditionally used for Telnet services.

Using Telnet is not secure it is an old protocol data (including passwords) are transmitted in clear text. Secure alternatives like SSH are recommended for remote command execution and data transmission.

Note that telnet is the client, telnetd is the server, and xinetd is a daemon that can manage telnetd among other services.

Part 7: SSH Connection

This part will explore Secure Shell (SSH), a protocol for securely accessing network services over an unsecured network. This section explains how to set up, manage, and use SSH connections.

1. Installing and Managing the SSH Service

Objective: Start the SSH service and make sure the service is running.

# apt update && apt install openssh-server -y
(Update package lists and install OpenSSH service)
# systemctl daemon-reload
(Reload system daemon to recognize new services)
# systemctl status ssh
(Check if SSH service is active and running)
# systemctl enabled ssh
(Enable SSH)
Or
# systemctl is-enabled ssh
(Enable SSH to start automatically at boot, it will confirm that SSH
is set to start on boot(
# systemctl start ssh
(start SSH)
# systemctl status ssh
(Check if SSH service is active and running)

Installing OpenSSH-server provides the SSH daemon needed for the server to accept connections. Ensuring the service is enabled at boot time enhances reliability, ensuring remote access is always available after restarts.

2. Establishing an SSH Connection from Windows to Kali Linux

Objective: Use SSH to connect from a Windows machine to a Kali Linux system and perform file operations.

PS C:\Windows\system32> ssh iritp@10.0.0.100
(Command executed from the Windows Command Prompt or PowerShell
Replace 'iritp' with your actual username and '10.0.0.100'
with the Linux machine's IP address)
# mkdir ~/Desktop/WINDOWS_1
(Once connected, create a new directory on the Desktop)
# ls ~/Desktop
(Verify that the directory has been created)

This step demonstrates how to initiate an SSH connection from a Windows system to a Kali Linux machine, allowing you to execute commands remotely. Creating a directory after connecting confirms the connection is functioning properly and that you have the necessary permissions.

Part 8: Configuring and Managing VSFTPD

This part will explore VSFTPD and how to install, configure, and manage file transfers.

1. Installing VSFTPD

Objective: Download the latest version of vsftpd.

# apt-get update && apt-get install vsftpd
(Update package lists to ensure you can access the latest version and Install VSFTPD)

2. Configuring and Starting VSFTPD

Objective: Configure VSFTPD and start the service.

# systemctl status vsftpd
(Check if VSFTPD is running before making changes)
# systemctl start vsftpd
(Start VSFTPD service if it's not already running)
# systemctl is-active vsftpd && echo "vsftpd is running" || echo "vsftpd is not running"
(Check if the service is active; confirm it's running)
# nano /etc/vsftpd.conf
(Edit the configuration file to set up basic FTP settings
Make necessary changes, then save and exit with CTRL+O, ENTER, and CTRL+X)
# service vsftpd restart
(Restart VSFTPD to apply the configuration changes)
# systemctl enable vsftpd.service
(Enable the service to start on boot)

Proper configuration ensures that your FTP server operates according to your security and operational standards. Starting the service and enabling it on boot ensures it’s always available when the system is on.

3. Transferring Files to a Windows Machine

Objective: Transfer a file from the Kali machine to the WINDOWS machine.

Make on kali machine new file in WINDOWS_1

# cd /home/iritp/Desktop/WINDOWS_1
# touch transferfile.txt
# ls
C:\Windows\system32> ftp 10.0.0.100
cd /home/iritp/Desktop/WINDOWS_1
Get transferfile.txt
(Command executed from the Windows Command Prompt or PowerShell PS , Connect to the FTP server at 10.0.0.100)

Demonstrating file transfer via FTP shows the basic functionality of your FTP server, allowing you to manage files between different systems.

4. Security Analysis with Wireshark

Objective: Run wireshark and reconnect to the FTP server (Kali machine). Try to find the password and explain why it is in plain text.

# wireshark
ftp
(on wireshark filter)
or
ftp.request.command
(on wireshark filter)

FTP (File Transfer Protocol) does not encrypt its data, including authentication credentials.

Better to use more secure Transfer Protocol:

· FTPS (File Transfer Protocol Secure) Extends FTP with TLS (Transport Layer Security) for encryption.

· SFTP (Secure File Transfer Protocol) uses Secure Shell (SSH) to encrypt all communications.

Part 9: Advanced Concepts and Practical Applications

This section explores key concepts in Linux, including system directories, encryption, and network configurations, providing deep insights into essential system administration skills.

1. Understanding ROOT Directories

Objective: What are ROOT directories? Choose three and explain them.

Root Directory (/): This is the top-level directory in a Linux file system. Everything on the system is under these directories, including all other directories and files. It is essential for the organization and structure of the file system.

/bin (Binary): Contains essential user executable programs (binaries), such as ls, cp, and rm. These are crucial for both users and system operations and must be available on boot, which is why they are stored in a separate directory under root.

/etc (Configuration): Houses system-wide configuration files. Changes to these files affect the system’s behavior. It is central for system administrators because it contains all the necessary settings and switches for system services.

/home: Each user has a directory under /home, providing storage for personal files, settings, and scripts. This separation ensures that users’ data remains organized and isolated from system files.

2. Explaining Key Security Terms

· Encryption: The process of encoding messages or information in such a way that only authorized parties can read it. It uses complex algorithms to transform readable data into a scrambled format that can only be deciphered with a specific key.

· Hashing: Converts data into a fixed-size string of bytes, typically a hash, which is usually a shorter, fixed-length value representing the original string. Hashing is used for creating data fingerprints and for data integrity checks.

· Symmetric Encryption: Uses a single key to encrypt and decrypt data. This method is fast and suitable for large volumes of data but requires secure key exchange protocols.

· Asymmetric Encryption: Utilizes a pair of keys (public and private) for encryption and decryption. This method is fundamental for secure data transmission over insecure networks like the internet.

3. SSH Configuration and Usage

Why Modify SSH Configuration: After installing SSH, configuration changes may be necessary to enhance security, limit user access, customize session settings, or adjust performance. It’s crucial to tailor the SSH service to meet specific security policies and operational requirements.

Another Configuration Example — Apache HTTP Server: Uses httpd.conf or apache2.conf for global settings, including server performance and security settings. Other files like ports.conf and .htaccess allow for more specialized configurations such as port management and directory-specific rules.

4. The Kernel in Linux

Definition and Role: The kernel is the core part of the operating system, managing the CPU, memory, and peripheral devices. It is the “bridge” between applications and the actual data processing done at the hardware level. The kernel makes it possible for the operating system to do its job efficiently.

5. Networking Between Virtual Machines

Steps to Connect Two VMs: Includes ensuring both VMs are operational, configuring network settings (like Bridged, NAT, or Host-Only networking), and optionally setting static IPs to facilitate communication. Verifying the network setup through commands like ifconfig and testing connectivity with ping ensures that the network is configured correctly.

6. What is Ping?

Ping Tool: A diagnostic utility that tests the reachability of a host on an IP network and measures the round-trip time for messages sent from the originating host to a destination computer.

7. File and Folder Permissions

Understanding Permissions (777): The notation 777 in Linux permissions represents read, write, and execute permissions for users, groups, and others. Each digit reflects specific rights, with 7 allowing full rights, thus ensuring comprehensive access.

8. Case Sensitivity in Linux File System

Creating Directories with Similar Names: Linux’s file system is case-sensitive, allowing directories such as “Folder” and “folder” to coexist as separate entities. This feature must be considered when managing files and directories to avoid confusion.

--

--

IritT
IritT

Written by IritT

In the world of cybersecurity, the strongest defense is knowledge. Hack the mind, secure the future.

No responses yet