DEV Community

Teniola
Teniola

Posted on

Basic Linux Administration

Its few months into my DevOps journey, I've engaged in extensive learning, relearning, and unlearning to build a strong technical foundation. Along the way, I've worked on various tasks and am now documenting my progress to share my learning experience. Here, I present a Basic Linux Administration task I worked on, detailing the foundational skills required for any successful devOps student.

*Introduction *

This article provides a comprehensive overview of essential Linux administration and server configuration tasks, structured to build foundational skills and progress to more advanced topics. The journey begins with Basic Linux Administration, aimed at equipping users with fundamental skills like managing user accounts, file permissions, and package installations. It then transitions to Networking and Web Servers, where users will learn key networking concepts and set up a simple web server. Finally, the guide delves into Advanced Linux Server Configuration, covering deeper configurations and optimizations to enhance server performance and security. Together, these tasks offer a structured pathway for mastering Linux server management.

  1. User Management

Step 1.1: Create and Manage User Accounts

Create a New User

To set up a new user account, the useradd command is used. This creates a user with a default home directory and configuration settings.

sudo groupadd groupname
Enter fullscreen mode Exit fullscreen mode

Set a Password for the New User
After creating the user account, passwd is used to assign a password. This step is critical to ensure security by allowing only authorized access.

sudo passwd username
Enter fullscreen mode Exit fullscreen mode

Step 1.2: Set Up Password Policies

Enforce Password Expiration
To enhance security, password expiration policies are configured using chage. Setting an expiration period ensures that users regularly update their passwords.
with this ,password expires every 90 days

sudo chage -M 90 username
Enter fullscreen mode Exit fullscreen mode

Verify Group Membership
The groups command allows you to verify a user’s group memberships, helping ensure correct permission assignment.

groups username
Enter fullscreen mode Exit fullscreen mode
  1. File System Navigation and Permissions Step 2.1: Navigate the Linux File System Change Directory The cd command allows movement through directories, essential for accessing files and folders within the system.
cd /path/to/directory
Enter fullscreen mode Exit fullscreen mode

List Directory Contents
Using ls -l provides a detailed list of files, including permissions, which is useful for managing and auditing file access.

ls -l
Enter fullscreen mode Exit fullscreen mode

Show Current Directory Path
pwd displays the current directory’s path, which helps verify your location in the file system.

pwd
Enter fullscreen mode Exit fullscreen mode

Step 2.2: Set File and Directory Permissions
Change File Permissions
The chmod command adjusts file permissions (read, write, execute) for the owner, group, and others, crucial for access control.

chmod 755 filename
Enter fullscreen mode Exit fullscreen mode

Change File Ownership
To assign a file to a specific user or group, use chown. This step helps manage ownership, especially in multi-user environments.

sudo chown user:group filename
Enter fullscreen mode Exit fullscreen mode

Check Permissions
Running ls -l filename provides a view of the file’s current permissions, helping confirm the correct settings.

ls -l filename
Enter fullscreen mode Exit fullscreen mode
  1. Package Management Step 3.1: Install Software Using apt (for Ubuntu) To install software on Ubuntu/Debian, first update the package list with apt update and then use apt install to install the package.
sudo apt update
sudo apt install packagename
Enter fullscreen mode Exit fullscreen mode

Step 3.2: Update Software
Using apt
The command apt update && apt upgrade ensures all installed packages are up-to-date.

sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Step 3.3: Remove Software
Using apt
Use apt remove to uninstall unwanted software on Ubuntu.

sudo apt remove packagename
Enter fullscreen mode Exit fullscreen mode
  1. Bash Scripting Step 4.1: Create a Simple Bash Script (user_report.sh) Open a New File Use a text editor like nano or vim to create the script file.
nano user_report.sh
Enter fullscreen mode Exit fullscreen mode

Add the Following Script Content
This script generates a report displaying the number of active users and available disk space.

#!/bin/bash
echo "User Report"
echo "-----------"
echo "Number of users on the system:"
who | wc -l
echo ""
echo "Disk Space Report"
echo "-----------------"
df -h /
Enter fullscreen mode Exit fullscreen mode

Save and Close the Script
Save your changes in the editor. In nano, use CTRL+O to save and CTRL+X to exit.

Step 4.2: Make the Script Executable
Add Execute Permissions
Make the script executable with chmod +x. This allows it to be run directly.

chmod +x user_report.sh
Enter fullscreen mode Exit fullscreen mode

Step 4.3: Run the Script
Execute the Script
Run the script to confirm it displays the user count and disk space information correctly.

./user_report.sh

Set Minimum Password Age
The minimum password age prevents users from changing their passwords too frequently, which can disrupt security protocols

sudo chage -m 1 username
Enter fullscreen mode Exit fullscreen mode

Step 1.3: Manage User Groups
Create a Group
Groups help organize users with similar permissions. To create a new group, use groupadd.

sudo groupadd groupname
Enter fullscreen mode Exit fullscreen mode

Add a User to a Group
Adding a user to a group with usermod grants them the permissions associated with that group, aiding in efficient permission management.

sudo usermod -aG groupname username
Enter fullscreen mode Exit fullscreen mode

Verify Group Membership
The groups command allows you to verify a user’s group memberships, helping ensure correct permission assignment.

groups username
Enter fullscreen mode Exit fullscreen mode

Verify Group Membership
The groups command allows you to verify a user’s group memberships, helping ensure correct permission assignment.

groups username

  1. File System Navigation and Permissions Step 2.1: Navigate the Linux File System Change Directory The cd command allows movement through directories, essential for accessing files and folders within the system.
cd /path/to/directory
Enter fullscreen mode Exit fullscreen mode

List Directory Contents
Using ls -l provides a detailed list of files, including permissions, which is useful for managing and auditing file access.

ls -l
Enter fullscreen mode Exit fullscreen mode

Show Current Directory Path
pwd displays the current directory’s path, which helps verify your location in the file system.

pwd
Enter fullscreen mode Exit fullscreen mode

Step 2.2: Set File and Directory Permissions
Change File Permissions
The chmod command adjusts file permissions (read, write, execute) for the owner, group, and others, crucial for access control.

chmod 755 filename
Enter fullscreen mode Exit fullscreen mode

Change File Ownership
To assign a file to a specific user or group, use chown. This step helps manage ownership, especially in multi-user environments.

sudo chown user:group filename
Enter fullscreen mode Exit fullscreen mode

Check Permissions
Running ls -l filename provides a view of the file’s current permissions, helping confirm the correct settings.

ls -l filename
Enter fullscreen mode Exit fullscreen mode
  1. Package Management Step 3.1: Install Software Using apt (for Ubuntu) To install software on Ubuntu/Debian, first update the package list with apt update and then use apt install to install the package.
sudo apt update
sudo apt install packagename
Enter fullscreen mode Exit fullscreen mode

Step 3.2: Update Software
Using apt
The command apt update && apt upgrade ensures all installed packages are up-to-date.

sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Step 3.3: Remove Software
Using apt
Use apt remove to uninstall unwanted software on Ubuntu.

sudo apt remove packagename
Enter fullscreen mode Exit fullscreen mode
  1. Bash Scripting Step 4.1: Create a Simple Bash Script (user_report.sh) Open a New File Use a text editor like nano or vim to create the script file.
nano user_report.sh
Enter fullscreen mode Exit fullscreen mode

Add the Following Script Content
This script generates a report displaying the number of active users and available disk space.

#!/bin/bash
echo "User Report"
echo "-----------"
echo "Number of users on the system:"
who | wc -l
echo ""
echo "Disk Space Report"
echo "-----------------"
df -h /
Enter fullscreen mode Exit fullscreen mode

Save and Close the Script
Save your changes in the editor. In nano, use CTRL+O to save and CTRL+X to exit.

Step 4.2: Make the Script Executable
Add Execute Permissions
Make the script executable with chmod +x. This allows it to be run directly.

chmod +x user_report.sh
Enter fullscreen mode Exit fullscreen mode

Step 4.3: Run the Script
Execute the Script
Run the script to confirm it displays the user count and disk space information correctly.

./user_report.sh

Top comments (0)