Skip to content

younes-bd/LinuxCommandsFileManage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 

Repository files navigation

File permissions in Linux

Description

The research team at my organization needs to update the file permissions for certain files and directories within the projects directory. The permissions do not currently reflect the level of authorization that should be given. Checking and updating these permissions will help keep their system secure. To complete this task, I performed the following tasks:

Check file and directory details:

The following code demonstrates how I used Linux commands to determine the existing permissions set for a specific directory in the file system.

Disk Sanitization Steps

The first line of the screenshot displays the command I entered, and the other lines display the output. The code lists all contents of the projects directory. I used the ls command with the -la option to display a detailed listing of the file contents that also returned hidden files. The output of my command indicates that there is one directory named drafts, one hidden file named .project_x.txt, and five other project files. The 10-character string in the first column represents the permissions set on each file or directory.

Describe the permissions string:

The 10-character string can be deconstructed to determine who is authorized to access the file and their specific permissions. The characters and what they represent are as follows:

  • 1st character: This character is either a d or hyphen (-) and indicates the file type. If it’s a d, it’s a directory. If it’s a hyphen (-), it’s a regular file.
  • 2nd-4th characters: These characters indicate the read (r), write (w), and execute (x) permissions for the user. When one of these characters is a hyphen (-) instead, it indicates that this permission is not granted to the user.
  • 5th-7th characters: These characters indicate the read (r), write (w), and execute (x) permissions for the group. When one of these characters is a hyphen (-) instead, it indicates that this permission is not granted for the group.
  • 8th-10th characters: These characters indicate the read (r), write (w), and execute (x) permissions for other. This owner type consists of all other users on the system apart from the user and the group. When one of these characters is a hyphen (-) instead, that indicates that this permission is not granted for other.

For example, the file permissions for project_t.txt are -rw-rw-r--. Since the first character is a hyphen (-), this indicates that project_t.txt is a file, not a directory. The second, fifth, and eighth characters are all r, which indicates that user, group, and other all have read permissions. The third and sixth characters are w, which indicates that only the user and group have write permissions. No one has execute permissions for project_t.txt.

Change file permissions:

The organization determined that other shouldn't have write access to any of their files. To comply with this, I referred to the file permissions that I previously returned. I determined project_k.txt must have the write access removed for other.
The following code demonstrates how I used Linux commands to do this:

Disk Sanitization Steps
The first two lines of the screenshot display the commands I entered, and the other lines display the output of the second command. The chmod command changes the permissions on files and directories. The first argument indicates what permissions should be changed, and the second argument specifies the file or directory. In this example, I removed write permissions from other for the project_k.txt file. After this, I used ls -la to review the updates I made.

Change file permissions on a hidden file:

The research team at my organization recently archived project_x.txt. They do not want anyone to have write access to this project, but the user and group should have read access.
The following code demonstrates how I used Linux commands to change the permissions:

Disk Sanitization Steps


The first two lines of the screenshot display the commands I entered, and the other lines display the output of the second command. I know .project_x.txt is a hidden file because it starts with a period (.). In this example, I removed write permissions from the user and group, and added read permissions to the group. I removed write permissions from the user with u-w. Then, I removed write permissions from the group with g-w, and added read permissions to the group with g+r.

Change directory permissions:

My organization only wants the researcher2 user to have access to the drafts directory and its contents. This means that no one other than researcher2 should have execute permissions.
The following code demonstrates how I used Linux commands to change the permissions:

Disk Sanitization Steps

Summary:

I changed multiple permissions to match the level of authorization my organization wanted for files and directories in the projects directory. The first step in this was using ls -la to check the permissions for the directory. This informed my decisions in the following steps. I then used the chmod command multiple times to change the permissions on files and directories.

Vulnerability Scanning with Nessus

Description:

As a cybersecurity analyst, you were tasked with performing a vulnerability assessment on your organization's internal network using the Nessus vulnerability scanner.

Linux Commands:

# Start Nessus in a Docker container (if Docker is used)
docker run -d --name nessus -p 8834:8834 -e "NESSUS_LICENSE=your-activation-code" nessus/nessus
# Open a web browser and navigate to Nessus web interface
# Login to the Nessus web interface, configure the scan, and initiate the vulnerability scan

Summary:

This project involved setting up and running a Nessus vulnerability scan to identify potential security issues within our organization's network. The Nessus scanner was deployed within a Docker container for ease of use. By conducting this scan, we gained insights into vulnerabilities and areas for security improvement.

Security Patch Management

Description:

Your organization needs to apply security patches to a Linux server to address known vulnerabilities and improve system security.

Linux Commands:

# Update package repositories
sudo apt update

# Upgrade installed packages, applying available security patches
sudo apt upgrade

# Review available security patches
sudo apt list --upgradable

# Install specific security updates
sudo apt install package-name

# Apply kernel security updates
sudo reboot

Summary:

In this project, we focused on enhancing system security by applying security patches to a Linux server. We began by updating the package repositories and upgrading installed packages to ensure all security patches were in place. This proactive approach helps safeguard our systems against known vulnerabilities.

Security Hardening with IPTables

Description:

You're tasked with configuring IPTables to restrict network traffic on a Linux server. Security hardening includes allowing only necessary services and blocking others.

Linux Commands:

# Allow SSH (replace xx.xx.xx.xx with your IP)
sudo iptables -A INPUT -p tcp --dport 22 -s xx.xx.xx.xx -j ACCEPT

# Allow HTTP and HTTPS traffic
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# Drop all other incoming traffic
sudo iptables -A INPUT -j DROP

# Save the rules
sudo iptables-save > /etc/iptables.rules

# Enable IPTables on boot
sudo systemctl enable netfilter-persistent

Summary:

This project focused on enhancing network security through the configuration of IPTables on a Linux server. By explicitly allowing only necessary services and blocking all other incoming traffic, we reduce the attack surface and fortify our system against potential threats.

System Log Analysis

Description:

You've been monitoring system logs to detect unusual activities and potential security incidents. This is a critical task for a cybersecurity analyst.

Linux Commands:

# Check the system logs (e.g., syslog)
cat /var/log/syslog

# Search for specific keywords (e.g., 'suspicious activity')
grep 'suspicious activity' /var/log/syslog

# Analyze authentication logs
cat /var/log/auth.log

# Monitor real-time logs
tail -f /var/log/syslog

Summary:

In this project, we delved into system log analysis, a vital aspect of cybersecurity monitoring. We examined various system logs, searched for specific keywords, and monitored real-time logs to identify potential security incidents and unusual activities. This ongoing monitoring is essential for maintaining a secure environment.

Intrusion Detection with Snort

Description:

You've configured Snort, an intrusion detection system, to monitor network traffic for signs of suspicious or malicious activity.

Linux Commands:

# Start Snort in IDS mode with a specific configuration file
sudo snort -q -A console -q -c /etc/snort/snort.conf -i eth0

# Analyze Snort logs for alerts
cat /var/log/snort/alert

# Review Snort rules and customize for your network
sudo nano /etc/snort/rules/local.rules

Summary:

This project revolved around setting up and configuring Snort, an intrusion detection system, to monitor network traffic for signs of suspicious or malicious activity. By analyzing Snort logs and customizing rules, we enhance our network's security posture and strengthen our ability to detect and respond to potential intrusions.

Network Scanning with Nmap

Description:

Your organization requested a network scan to identify open ports and services on a target host. You performed this scan using the Nmap network scanning tool.

Linux Commands:

# Scan a target host for open ports
nmap target-host

# Scan a range of IP addresses
nmap 192.168.1.1-50

# Scan a specific port range
nmap -p 80-100 target-host

# Save the scan results to a file
nmap -oN scan-results.txt target-host

Summary:

This project involved conducting a network scan on a target host using Nmap. The scan revealed open ports and services on the target, providing valuable insights into potential vulnerabilities. The results were saved for further analysis and to assist in securing the network.

Server Hardening with SSH Configuration

Description:

Your task was to enhance the security of a Linux server by configuring SSH (Secure Shell) to use key-based authentication, disabling password-based logins, and implementing other security measures.

Linux Commands:

# Generate an SSH key pair (if not already generated)
ssh-keygen -t rsa

# Copy the public key to the remote server for key-based authentication
ssh-copy-id user@remote-host

# Edit SSH server configuration
sudo nano /etc/ssh/sshd_config

# Disable password-based logins
PasswordAuthentication no

# Restart the SSH service to apply changes
sudo systemctl restart ssh

Summary:

In this project, the focus was on improving server security by configuring SSH for key-based authentication and disabling password-based logins. These measures bolstered the server's security posture, making it less vulnerable to unauthorized access.

Incident Response Simulation

Description:

Your organization conducted an incident response simulation to test the effectiveness of the response plan in the event of a security incident.

Linux Commands:

# Simulate a security incident by creating a test file
touch /var/test-incident-file.txt

# Generate log entries related to the incident
echo "Unauthorized access detected" >> /var/log/security.log

# Execute the incident response plan
Follow predefined procedures for incident containment, investigation, and recovery

Summary:

In this incident response simulation, you practiced the initial steps taken in response to a security incident. By creating a test incident file and generating corresponding log entries, you assessed the effectiveness of the incident response plan and made improvements as needed.

Forensic Analysis of Suspicious File

Description:

You were tasked with analyzing a suspicious file to determine its origin and whether it poses a security threat.

Linux Commands:

# Create a copy of the suspicious file for analysis
cp suspicious-file /var/forensics/

# Analyze the file using various forensic tools
strings /var/forensics/suspicious-file
hexdump -C /var/forensics/suspicious-file
file /var/forensics/suspicious-file

# Review system logs for any related activities
cat /var/log/auth.log

Summary:

This project involved conducting a forensic analysis of a suspicious file to identify potential security risks. By using Linux commands and forensic tools, you gained insights into the file's content and origin, aiding in the organization's security decision-making.

Endpoint Security Management with SELinux

Description:

Your task was to implement SELinux (Security-Enhanced Linux) policies to enhance endpoint security on Linux systems.

Linux Commands:

# Check the current SELinux status
sestatus

# Install SELinux utilities (if not already installed)
sudo yum install policycoreutils

# Modify SELinux policy to control access for specific processes
sudo semanage permissive -a httpd_t

# Apply SELinux policies and relabel the file system
sudo touch /.autorelabel
sudo reboot

Summary:

In this project, you focused on improving endpoint security by implementing SELinux policies. By controlling access for specific processes, you strengthened security controls and enhanced the overall security of Linux systems.

Linux Kernel Patching for Security

Description:

Your organization required a critical security patch to be applied to the Linux kernel to address a known vulnerability.

Linux Commands:

# Check the current kernel version
uname -r

# Download the latest kernel patch from the official source
wget https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.x.x.tar.xz

# Extract the kernel source code
tar -xvf linux-5.x.x.tar.xz

# Apply the security patch
cd linux-5.x.x
patch -p1 < security-patch.diff

# Recompile and install the patched kernel
make && make modules_install && make install

# Reboot the system to load the new kernel
reboot

Summary:

In this project, you demonstrated your ability to apply a critical security patch to the Linux kernel, thus addressing a known vulnerability and enhancing the system's security.

Intrusion Detection System (IDS) Configuration

Description:

Your task was to set up an IDS (Intrusion Detection System) on a Linux server to monitor network traffic for potential security threats.

Linux Commands:

# Install the Snort IDS system
sudo apt-get install snort

# Configure Snort rules and policies
sudo nano /etc/snort/snort.conf
sudo nano /etc/snort/rules/local.rules

# Start the Snort IDS service
sudo systemctl start snort
sudo systemctl enable snort

Summary:

In this project, you successfully configured an IDS on a Linux server, allowing it to monitor network traffic for suspicious activity and potential security threats. This is a crucial step in enhancing network security.

Log Analysis for Security Monitoring

Description:

Your organization needed to improve its security monitoring by analyzing log files to detect and respond to security incidents.

Linux Commands:

# Collect and analyze system logs
grep "Unauthorized access" /var/log/auth.log
grep "malware detected" /var/log/syslog

# Create custom log analysis scripts
nano analyze-logs.sh

# Automate log analysis with cron jobs
crontab -e

Summary:

This project focused on setting up log analysis processes on a Linux system to monitor for unauthorized access and malware detection. By creating custom log analysis scripts and automating the analysis, you improved security monitoring capabilities.

Hardening SSH Configuration

Description:

You were tasked with enhancing the security of SSH by modifying its configuration to adhere to best practices.

Linux Commands:

# Edit SSH server configuration
sudo nano /etc/ssh/sshd_config

# Disable root login
PermitRootLogin no

# Set idle timeout for SSH sessions
ClientAliveInterval 300
ClientAliveCountMax 0

# Implement rate-limiting for login attempts
MaxAuthTries 3

# Restart the SSH service to apply changes
sudo systemctl restart ssh

Summary: In this project, you improved the security of SSH by modifying its configuration to disable root logins, set an idle timeout, and implement rate-limiting for login attempts. These measures enhance the security of remote access to the system.

Security Compliance Auditing with Lynis

Description:

Your organization needed to conduct a security compliance audit on Linux servers to identify vulnerabilities and ensure adherence to security best practices.

Linux Commands:

# Install Lynis, a security auditing tool
wget https://cisofy.com/files/lynis-3.x.x.tar.gz
tar -xvf lynis-3.x.x.tar.gz

# Run a security audit with Lynis
cd lynis
sudo ./lynis audit system

# Review the audit report for findings and recommendations
cat /var/log/lynis-report.dat

Summary:

This project involved using Lynis, a security auditing tool, to conduct a comprehensive audit of Linux systems. The audit report provided valuable insights into vulnerabilities and recommendations for improving security and compliance.

Disk Encryption Implementation

Description:

Your organization required sensitive data on Linux servers to be encrypted to protect it in case of unauthorized access.

Linux Commands:

# Install encryption tools (e.g., LUKS)
sudo apt-get install cryptsetup

# Create an encrypted volume
sudo cryptsetup luksFormat /dev/sdX

# Open the encrypted volume
sudo cryptsetup open /dev/sdX encrypted-volume

# Format the encrypted volume with a filesystem (e.g., ext4)
sudo mkfs.ext4 /dev/mapper/encrypted-volume

# Mount the encrypted volume
sudo mount /dev/mapper/encrypted-volume /mnt/encrypted-data

Summary:

This project involved implementing disk encryption on Linux servers to protect sensitive data. By creating an encrypted volume, formatting it with a filesystem, and mounting it, you ensured the security of sensitive information.

Implementing Two-Factor Authentication (2FA) for SSH

Description:

Your organization needed to enhance the security of SSH logins by implementing two-factor authentication for user accounts.

Linux Commands:

# Install the necessary packages
sudo apt-get install libpam-google-authenticator

# Configure 2FA for a specific user
google-authenticator

# Edit the SSH PAM configuration
sudo nano /etc/pam.d/sshd

# Add the following line to enable 2FA for SSH
auth required pam_google_authenticator.so

# Restart the SSH service
sudo systemctl restart ssh

Summary:

In this project, you improved SSH security by implementing two-factor authentication (2FA) for user accounts. 2FA adds an extra layer of security to the login process.

Setting Up a Linux Bastion Host

Description:

Your organization needed to establish a secure bastion host, also known as a jump host, to control and audit remote access to internal servers.

Linux Commands:

# Configure the bastion host server
sudo apt-get install openssh-server

# Create SSH keys for administrators
ssh-keygen -t rsa

# Install the public keys on the bastion host
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

# Configure SSH to allow gateway functionality
sudo nano /etc/ssh/sshd_config

,Summary:

In this project, you set up a Linux bastion host, a critical component of a secure remote access solution. The bastion host controls and logs access to internal servers.

Linux Disk Space Monitoring

Description:

Your organization required monitoring of disk space on multiple Linux servers to prevent out-of-space issues.

Linux Commands:

# Check disk space usage
df -h

# Set up automated disk space alerts
nano disk-space-monitor.sh

# Schedule the script with cron
crontab -

Summary:

This project focused on implementing disk space monitoring to prevent critical server out-of-space issues. You created a script and scheduled it with cron to provide automated alerts.

Firewall Rule Configuration with iptables

Description:

Your organization needed to configure firewall rules on a Linux server to control incoming and outgoing network traffic.

Linux Commands:

# Install iptables
sudo apt-get install iptables

# Define the rules for the firewall
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -j DROP

# Save the firewall rules
sudo apt-get install iptables-persistent

Summary:

In this project, you demonstrated the capability to configure firewall rules using iptables to control incoming and outgoing network traffic on a Linux server.

System Log Rotation and Management

Description:

Your organization needed to set up log rotation and management to ensure that log files do not consume excessive disk space.

Linux Commands:

# Configure log rotation
sudo nano /etc/logrotate.conf

# Define log rotation settings for specific log files
sudo nano /etc/logrotate.d/app-logs

# Test log rotation settings
logrotate -d /etc/logrotate.conf

Summary:

This project involved setting up log rotation and management to maintain an organized log history while preventing log files from occupying too much disk space.

Linux User Account Auditing

Description:

Your organization required auditing of user accounts on Linux servers to track and log changes and access.

Linux Commands:

# Enable user auditing
sudo nano /etc/audit/auditd.conf
sudo service auditd restart

# Monitor user account changes
auditctl -a always,exit -F arch=b64 -S usermod -k usermod_changes
auditctl -a always,exit -F arch=b64 -S passwd -k passwd_changes

# Review audit logs
ausearch -k usermod_changes

Summary:

In this project, you demonstrated the ability to enable user account auditing on Linux servers, enhancing security by tracking and logging changes and access.

Implementing File Integrity Monitoring (FIM)

Description:

Your organization needed to enhance security by implementing File Integrity Monitoring to detect unauthorized changes to critical system files.

Linux Commands:

# Install a FIM tool like Tripwire
sudo apt-get install tripwire

# Initialize and configure Tripwire
sudo tripwire --init
sudo tripwire --update-policy

# Check for changes in the file system
sudo tripwire --check

Summary:

In this project, you improved security by implementing File Integrity Monitoring (FIM) with Tripwire. FIM helps detect and alert on unauthorized changes to system files.

Implementing Log Management with ELK Stack

Description:

Your organization required central log management and analysis to monitor and respond to security events effectively.

Linux Commands:

# Install and configure the ELK Stack (Elasticsearch, Logstash, Kibana)
sudo apt-get install elasticsearch logstash kibana

# Set up Logstash to collect and filter logs
# Configure Kibana for log visualization

# Forward logs from Linux servers to the ELK Stack

Summary:

This project involved setting up a powerful log management solution using the ELK Stack to aggregate, analyze, and visualize log data, enhancing the organization's security posture.

Hardening SSH Security

Description:

Your organization wanted to harden the security of the SSH service on Linux servers to prevent unauthorized access.

Linux Commands:

# Modify SSH configuration
sudo nano /etc/ssh/sshd_config

# Implement security measures like disabling root login, using key authentication, and limiting login attempts

Summary:

In this project, you focused on hardening SSH security to protect Linux servers from unauthorized access and attacks.

Implementing Network Intrusion Detection with Snort

Description:

Your organization needed a network intrusion detection system to monitor network traffic and detect suspicious or malicious activity.

Linux Commands:

# Install Snort
sudo apt-get install snort

# Configure Snort rules and network interfaces
sudo nano /etc/snort/snort.conf

# Start Snort in Network Intrusion Detection mode
sudo snort -q -A console -q -q -c /etc/snort/snort.conf

Summary:

In this project, you implemented network intrusion detection using Snort, enhancing the organization's ability to detect and respond to network-based threats.

Implementing Full Disk Encryption with LUKS

Description:

Your organization needed to secure sensitive data on Linux laptops by implementing full disk encryption.

Linux Commands:

# Install LUKS (Linux Unified Key Setup)
sudo apt-get install cryptsetup

# Initialize LUKS encryption
sudo cryptsetup --verbose --verify-passphrase luksFormat /dev/sdX

# Create an encrypted partition and mount it
sudo cryptsetup luksOpen /dev/sdX my_encrypted_partition

Summary:

In this project, you implemented full disk encryption using LUKS to protect sensitive data on Linux laptops.

These projects demonstrate your expertise in Linux-based security practices, further enriching your portfolio as a cybersecurity analyst.

Implementing System Updates and Patch Management

NDescription:

Your organization required a robust system for managing system updates and patches to ensure security and stability.

Linux Commands:

# Update package lists
sudo apt update

# Upgrade packages
sudo apt upgrade

# Automate updates with unattended-upgrades
sudo apt install unattended-upgrades

Summary: In this project, you established a reliable system for managing system updates and patches, enhancing the organization's security and stability.

Setting Up and Securing a Web Server with Apache

Description:

Your organization needed to deploy a web server for hosting company websites and web applications securely.

Linux Commands:

# Install Apache web server
sudo apt-get install apache2

# Configure firewall settings
sudo ufw allow 'Apache'

# Enable HTTPS with Let's Encrypt
sudo apt-get install certbot python3-certbot-apache

Summary: In this project, you set up and secured an Apache web server, ensuring that websites and applications are hosted securely and efficiently.

Implementing Centralized User Authentication with LDAP

Description:

Your organization wanted to centralize user authentication to simplify user management across multiple Linux servers.

Linux Commands:

# Install and configure an LDAP server
sudo apt-get install slapd ldap-utils

# Create LDAP entries for users and groups
sudo ldapadd -x -D cn=admin,dc=example,dc=com -W -f user.ldif

Summary: In this project, you implemented a centralized user authentication system using LDAP, simplifying user management and enhancing security.

Creating Automated Backup Solution

Description:

Your organization needed automated backup solutions to ensure data integrity and availability in case of data loss or system failures.

Linux Commands:

# Create backup scripts
nano backup_script.sh

# Schedule automated backups with cron
crontab -e

Summary: In this project, you designed and implemented automated backup solutions, safeguarding critical data and ensuring quick recovery in the event of data loss or system failures.

Setting Up Virtualization with KVM/QEMU

Description:

Your organization wanted to create a virtualized environment for efficient resource management and scalability.

Linux Commands:

# Install KVM and QEMU
sudo apt-get install qemu-kvm libvirt-bin

# Create and manage virtual machines
virt-install --name=VMname --memory=1024 --vcpus=2 --disk size=10

Summary: In this project, you set up virtualization using KVM/QEMU, providing your organization with a flexible and efficient IT environment.

These projects showcase your skills as a Linux system administrator and enrich your portfolio with examples of critical system administration tasks.

Implementing a Secure SSH Configuration

Description:

Your organization needed to enhance security by configuring SSH (Secure Shell) for secure remote access to Linux servers.

Linux Commands:

# Edit SSH configuration file
sudo nano /etc/ssh/sshd_config

# Implement key-based authentication

Summary: In this project, you improved server security by configuring SSH to allow key-based authentication, reducing the risk of unauthorized access.

Deploying a Docker Containerization Environment

Description:

Your organization aimed to streamline application deployment and scaling by implementing a Docker containerization environment.

Linux Commands:

# Install Docker
sudo apt-get install docker.io

# Create and manage Docker containers
docker run -d -p 80:80 nginx

Summary: In this project, you established a Docker containerization environment, simplifying application deployment and management.

Configuring a Centralized Logging System

Description:

Your organization required a centralized logging system to monitor and analyze logs across multiple servers.

Linux Commands:

# Install and configure the ELK Stack (Elasticsearch, Logstash, Kibana)

Summary:

In this project, you set up a centralized logging system using the ELK Stack, enabling efficient log monitoring and analysis.

Implementing Firewall Rules with IPtables

Description:

Your organization needed to enhance network security by setting up custom firewall rules using IPtables.

Linux Commands:

# Create custom firewall rules
sudo iptables -A INPUT -p tcp --dport 22 -j DROP

Summary: In this project, you improved network security by configuring custom firewall rules using IPtables, providing granular control over network traffic.

Creating an Automated Monitoring System with Nagios

Description:

Your organization wanted a robust monitoring system to track server performance and detect issues proactively.

Linux Commands:

# Install and configure Nagios

Summary: In this project, you established an automated monitoring system with Nagios, ensuring early issue detection and server performance tracking.

Optimizing System Performance with Linux Tweaks

Description:

Your organization aimed to enhance system performance through various Linux performance tweaks.

Linux Commands:

# Implement system optimizations such as optimizing swap usage or file system changes.

Summary: In this project, you optimized system performance by applying various Linux tweaks, ensuring optimal system operation.

Creating Custom Bash Scripts for Automation

Description:

Your organization needed custom automation scripts to streamline routine tasks.

Linux Commands:

# Write custom Bash scripts to automate specific tasks.

Summary:

In this project, you developed custom Bash scripts to automate recurring tasks, increasing operational efficiency.

These projects demonstrate your expertise as a Linux system administrator and contribute valuable examples to your portfolio.

Automate Website Backup

Description:

Automate the backup of a website's files and database at regular intervals.
#!/bin/bash

# Website backup script
# Replace the placeholders with your website's specific details

# Set backup directory
backup_dir="/path/to/backup"

# Set website root directory
website_dir="/path/to/website"

# Set database credentials
db_user="username"
db_pass="password"
db_name="database_name"

# Create a backup folder with the current date
backup_folder="$backup_dir/backup-$(date +\%Y\%m\%d)"

# Create the directory
mkdir -p $backup_folder

# Backup website files
cp -r $website_dir $backup_folder

# Backup the database
mysqldump -u $db_user -p$db_pass $db_name > $backup_folder/database.sql

# Optionally, compress the backup folder
tar -czf $backup_folder.tar.gz $backup_folder

# Remove the uncompressed folder if needed
# rm -r $backup_folder

Summary:

This script automates the process of backing up a website's files and database, making it easy to schedule regular backups.

Automate Log Cleanup

Description:

Automate the cleanup of log files in a specified directory.

bash script:

#!/bin/bash

# Log cleanup script
# Set the path to the log directory
log_dir="/path/to/logs"

# Set the maximum number of log files to keep
max_logs=10

# Clean up log files
find $log_dir -type f -mtime +$max_logs -exec rm {} \;

Summary:

This script automates log file cleanup by removing older log files, helping to manage disk space.

Automate File Transfer to a Remote Server

Description:

Automate the transfer of files to a remote server using SCP.

bash script:

#!/bin/bash

# File transfer script
# Replace placeholders with your server and file details

# Set source file
source_file="/path/to/local/file"

# Set destination server
server="username@remote_server_ip"

# Set destination directory
destination_dir="/path/to/remote/directory"

# Transfer file to the remote server
scp $source_file $server:$destination_dir

Summary:

This script automates file transfers to a remote server, which is useful for routine data synchronization.

Automate Daily System Report Email

Description:

Automate the creation and email delivery of a daily system report.

bash script:

#!/bin/bash

# Daily system report script

# Generate a system report and save it to a file
report_file="/path/to/daily_report.txt"
echo "Daily System Report" > $report_file
date >> $report_file
free -h >> $report_file
df -h >> $report_file
# Add more system commands as needed

# Email the report
recipient="your@email.com"
subject="Daily System Report"

cat $report_file | mail -s "$subject" $recipient

Summary:

This script generates a daily system report and emails it to a specified recipient, automating daily system monitoring.

These Bash scripts showcase your automation skills and can be tailored to meet specific needs in your role as a system administrator.

Automate User Account Management

Description:

Automate the process of creating, updating, or deleting user accounts on a Linux system.

bash script:

#!/bin/bash

# User management script

# Action can be 'create', 'update', or 'delete'
action="create"
username="newuser"
fullname="New User"
homedir="/home/$username"
password="userpassword"

if [ "$action" == "create" ]; then
    # Create a new user
    useradd -m -d $homedir -c "$fullname" $username
    echo "$username:$password" | chpasswd
    passwd -e $username  # Force user to change password on first login
elif [ "$action" == "update" ]; then
    # Update user details
    usermod -c "$fullname" $username
    echo "$username:$password" | chpasswd
elif [ "$action" == "delete" ]; then
    # Delete a user
    userdel -r $username
fi

Summary:

This script automates user account management tasks like creating, updating, and deleting user accounts.

Automate Log Rotation

Description:

Automate log file rotation and compression to manage disk space efficiently.

bash script:

#!/bin/bash

# Log rotation script

# Set the path to the log directory
log_dir="/path/to/logs"

# Set the maximum number of log files to keep
max_logs=10

# Archive old logs
for logfile in $(find $log_dir -type f -mtime +$max_logs); do
    gzip $logfile
done

Summary:

This script automates log rotation by compressing old log files, keeping your log directory organized.

Automate Backup Verification

Description:

Automate the verification of backups by comparing files in the source and backup directories.

bash script:

#!/bin/bash

# Backup verification script

# Set the source and backup directories
source_dir="/path/to/source"
backup_dir="/path/to/backup"

# Use rsync to compare source and backup
rsync -n -a --delete $source_dir/ $backup_dir/

Summary:

This script uses rsync to compare the source and backup directories, helping ensure that backups are complete and accurate.

Automate Server Monitoring Alerts

Description:

Automate server monitoring and send alerts if resource usage exceeds predefined thresholds.

bash script:

#!/bin/bash

# Server monitoring and alert script

# Set thresholds for resource usage
cpu_threshold=80
memory_threshold=90

# Check CPU usage
cpu_usage=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}')
if (( $(echo "$cpu_usage > $cpu_threshold" | bc -l) )); then
    echo "High CPU usage: $cpu_usage%" | mail -s "Server Alert" admin@example.com
fi

# Check memory usage
memory_usage=$(free | awk '/Mem/{print $3/$2 * 100.0}')
if (( $(echo "$memory_usage > $memory_threshold" | bc -l) )); then
    echo "High memory usage: $memory_usage%" | mail -s "Server Alert" admin@example.com
fi

Summary:

This script automates server monitoring and sends email alerts when CPU or memory usage exceeds predefined thresholds.

These Bash scripts can help you automate various tasks as a system administrator, saving time and reducing the risk of errors in routine operations.

Automate Daily System Maintenance

Description:

Automate routine system maintenance tasks, such as updating packages and cleaning up temporary files.

bash script:

#!/bin/bash

# Daily system maintenance script

# Update package repositories and upgrade packages
apt-get update
apt-get upgrade -y

# Clean up temporary files
apt-get autoclean
apt-get autoremove -y

# Send a notification
echo "System maintenance completed on $(date)" | mail -s "System Maintenance" admin@example.com

Summary:

This script automates daily system maintenance tasks, keeping the system up to date and cleaning up unnecessary files.

Automate Web Server Log Analysis

Description:

Automate the analysis of web server logs to generate usage statistics.

bash script:

#!/bin/bash

# Web server log analysis script

# Set log file path
log_file="/var/log/apache/access.log"

# Generate usage statistics using AWK
awk '{print $1}' $log_file | sort | uniq -c | sort -n > usage_stats.txt

# Send the statistics to an email address
mail -s "Web Server Usage Stats" admin@example.com < usage_stats.txt

Summary:

This script automates the analysis of web server logs and sends the usage statistics to an email address.

Automate Firewall Rule Updates

Description:

Automate the process of updating firewall rules to allow or deny specific IP addresses.

bash script:

#!/bin/bash

# Firewall rule update script

# Set the IP address to allow or deny
ip_address="192.168.1.100"

# Add a rule to allow the IP address
iptables -A INPUT -s $ip_address -j ACCEPT

# Save the firewall rules
iptables-save > /etc/iptables/rules.v4

Summary:

This script automates the process of adding or updating firewall rules to allow specific IP addresses.

Automate Disk Space Monitoring

Description:

Automate the monitoring of disk space usage and send alerts if space falls below a certain threshold.
#!/bin/bash

# Disk space monitoring script

# Set the threshold (in percentage) for alerting
threshold=90

# Get disk space usage
disk_usage=$(df -h / | awk 'NR==2{print $5}' | cut -d'%' -f1)

# Check if disk usage exceeds the threshold
if [ $disk_usage -ge $threshold ]; then
    echo "Disk space usage is at $disk_usage%" | mail -s "Disk Space Alert" admin@example.com
fi

Summary:

This script automates disk space monitoring and sends an email alert if disk space usage exceeds a defined threshold.

Automate Backup of Configuration Files

Description:

Automate the backup of important configuration files to ensure they can be easily restored if needed.
#!/bin/bash

# Configuration file backup script

# Set the backup directory
backup_dir="/backup/configs"

# List of configuration files to back up
config_files=("/etc/nginx/nginx.conf" "/etc/ssh/sshd_config" "/etc/apache2/httpd.conf")

# Create a timestamp for the backup folder
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
backup_folder="$backup_dir/configs_$timestamp"

# Create the backup directory
mkdir -p $backup_folder

# Copy each configuration file to the backup directory
for file in "${config_files[@]}"; do
    cp $file $backup_folder
done

# Tar and compress the backup folder
tar -czvf "$backup_folder.tar.gz" $backup_folder

# Remove the original backup folder
rm -rf $backup_folder

Summary:

This script automates the backup of important configuration files, compresses them, and stores them in a backup directory.

Automate User Account Management

Description:

Automate user account management tasks, such as creating, modifying, and deleting user accounts.

bash script:

#!/bin/bash

# User account management script

# Set the list of user accounts to create
users=("user1" "user2" "user3")

# Create user accounts
for user in "${users[@]}"; do
    useradd -m -s /bin/bash $user
    echo "Password123" | passwd --stdin $user
done

# Modify user account properties
usermod -g newgroup user1
usermod -aG additionalgroup user2

# Delete user accounts
userdel -r user3

Summary:

This script automates the management of user accounts, including account creation, modification, and deletion.

Automate Log Rotation

Description:

Automate log rotation for log files to prevent them from growing too large.

bash script:

#!/bin/bash

# Log rotation script

# Set the log file to rotate
log_file="/var/log/application.log"

# Set the maximum log file size in MB
max_size=10

# Check if the log file size exceeds the maximum size
if [ $(du -m $log_file | cut -f1) -gt $max_size ]; then
    # Rotate the log file
    mv $log_file "$log_file.1"
    touch $log_file
fi

Summary:

This script automates log rotation for a specific log file, ensuring that it does not exceed a defined maximum size.

Automate Software Updates

Description:

Automate the process of checking for and applying software updates on the system.

bash script:

#!/bin/bash

# Software update script

# Update package repositories
apt-get update

# Upgrade installed packages
apt-get upgrade -y

# Clean up after the update
apt-get autoremove -y
apt-get clean

Summary:

This script automates the software update process by updating package repositories, upgrading installed packages, and cleaning up the system.

Automate Daily System Health Check

Description:

Automate a daily system health check to ensure system resources are within acceptable limits and generate a report.

bash script:

#!/bin/bash

# Daily system health check script

# Log file for the report
log_file="/var/log/system_health.log"

# Get current date and time
current_datetime=$(date "+%Y-%m-%d %H:%M:%S")

# Check CPU and memory usage
cpu_usage=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}')
memory_usage=$(free -m | awk '/Mem/ {print $3}')

# Check disk space
disk_space=$(df -h | awk '/sda1/ {print $4}')

# Write the results to the log file
echo "Date and Time: $current_datetime" >> $log_file
echo "CPU Usage: $cpu_usage" >> $log_file
echo "Memory Usage: $memory_usage MB" >> $log_file
echo "Available Disk Space: $disk_space" >> $log_file

Summary:

This script automates a daily system health check and logs CPU usage, memory usage, and available disk space to a log file.

Automate Log File Monitoring

Description:

Automate the monitoring of log files for specific events or error messages and send email notifications.

bash script:

#!/bin/bash

# Log file monitoring script

# Log file to monitor
log_file="/var/log/application.log"

# Search for a specific error message in the log file
error_message="Error:"

# Email address to receive notifications
recipient="admin@example.com"

# Check for the error message
if grep -q "$error_message" $log_file; then
    # Send an email notification
    echo "Error found in log file $log_file" | mail -s "Log Error Notification" $recipient
fi

Summary:

This script automates log file monitoring for a specific error message and sends an email notification if the error is found.

Automate Firewall Rule Updates

Description:

Automate the process of updating firewall rules to allow or deny specific IP addresses or services.

bash script:

#!/bin/bash

# Firewall rule update script

# IP address or range to allow
allowed_ip="192.168.1.100"

# Port to open
port="22"

# Update firewall rule to allow the IP address and port
iptables -A INPUT -p tcp -s $allowed_ip --dport $port -j ACCEPT

Summary:

This script automates the update of firewall rules to allow a specific IP address and port.

Automate System Backup

Description:

Automate the system backup process to create regular backups of important system files.

bash script:

#!/bin/bash

# System backup script

# Directory to store backups
backup_dir="/backups/system"

# Create a timestamp for the backup folder
timestamp=$(date +"%Y-%m-%d")

# Create the backup directory
mkdir -p $backup_dir/$timestamp

# Backup important system files
cp -r /etc $backup_dir/$timestamp
cp -r /var/www $backup_dir/$timestamp

Summary:

This script automates the creation of system backups by copying important system files to a backup directory.

These additional Bash scripts can help system administrators streamline routine tasks and ensure the reliability and security of their systems.

Automate Log Rotation

Description:

Automate log rotation to prevent log files from consuming too much disk space.

bash script:

#!/bin/bash

# Log rotation script

# Log file to rotate
log_file="/var/log/application.log"

# Number of log files to keep
num_logs_to_keep=5

# Perform log rotation
mv $log_file $log_file.1

# Remove old log files
for ((i = $num_logs_to_keep; i > 1; i--)); do
  mv $log_file.$(($i - 1)) $log_file.$i
done

# Create an empty log file
touch $log_file

Summary:

This script automates log rotation by moving the current log file to a backup, removing old log files, and creating a new empty log file.

Automate User Account Management

Description:

Automate user account creation and management based on a list of users and their access levels.

bash script:

#!/bin/bash

# User account management script

# File containing user data (username:access_level)
user_data_file="users.txt"

# Read user data and create user accounts
while IFS=":" read -r username access_level; do
  useradd -m -s /bin/bash $username
  if [ "$access_level" == "admin" ]; then
    usermod -aG sudo $username
  fi
done < "$user_data_file"

Summary:

This script automates user account management by reading user data from a file and creating user accounts with appropriate access levels.

Automate System Updates

Description:

Automate the process of checking for and applying system updates.

bash script:

#!/bin/bash

# System update script

# Check for system updates
sudo apt update

# Upgrade system packages
sudo apt upgrade -y

Summary:

This script automates system updates by checking for updates and upgrading system packages.

Automate Database Backup

Description:

Automate the backup of a database, compress it, and store it with a timestamp.

bash script:

#!/bin/bash

# Database backup script

# Database connection details
db_user="username"
db_password="password"
db_name="mydb"

# Directory to store backups
backup_dir="/backups/database"

# Create a timestamp for the backup file
timestamp=$(date +"%Y%m%d%H%M%S")

# Backup the database and compress it
mysqldump -u $db_user -p$db_password $db_name | gzip > $backup_dir/backup_$timestamp.sql.gz

Summary:

This script automates the backup of a database, compresses it, and stores it in a directory with a timestamp.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors