Linux
OS-Mgmt
AmazonLinux
Setup

Amazon Linux Server Management Guide

1. Introduction

Amazon Linux is a Linux distribution provided by AWS that is optimized for use in the Amazon Web Services cloud environment. This guide will help you manage an Amazon Linux server effectively, from basic operations to troubleshooting.

2. Updating and Upgrading the System

2.1. Checking for Updates

Before updating, it's important to check for available updates.

sudo yum check-update

2.2. Updating the System

To update all installed packages to their latest versions, use:

sudo yum update -y

2.3. Upgrading the System

Amazon Linux 2 does not have a traditional "upgrade" command like Debian-based systems. Instead, keeping the system updated as shown above ensures you're running the latest version of packages.

3. Installing Packages

3.1. Installing a Package

To install a specific package, use the yum install command:

sudo yum install <package_name> -y

Example:

sudo yum install httpd -y

3.2. Searching for a Package

To search for a package, use:

yum search <package_name>

3.3. Removing a Package

To remove a package, use the yum remove command:

sudo yum remove <package_name> -y

4. Basic Commands

4.1. Navigating the File System

  • List files and directories:
    ls
  • Change directory:
    cd /path/to/directory
  • Print the current working directory:
    pwd

4.2. File Operations

  • Create a file:
    touch filename.txt
  • View file contents:
    cat filename.txt
  • Copy a file:
    cp source.txt destination.txt
  • Move or rename a file:
    mv oldname.txt newname.txt
  • Delete a file:
    rm filename.txt

4.3. Managing Users and Groups

  • Add a new user:
    sudo useradd username
  • Set a password for a user:
    sudo passwd username
  • Delete a user:
    sudo userdel username
  • Add a user to a group:
    sudo usermod -aG groupname username

5. System Monitoring and Troubleshooting

5.1. System Resource Monitoring

  • Check system uptime:
    uptime
  • View running processes:
    top
  • Check memory usage:
    free -m
  • Check disk usage:
    df -h

5.2. Networking Commands

  • Check network interfaces:
    ifconfig
  • Test network connectivity:
    ping <hostname_or_IP>
  • Display routing table:
    netstat -rn

5.3. Log Management

  • View system logs:
    sudo tail -f /var/log/messages
  • View SSH logs:
    sudo tail -f /var/log/secure
  • View Apache logs:
    sudo tail -f /var/log/httpd/access_log
    sudo tail -f /var/log/httpd/error_log

5.4. Service Management

  • Start a service:
    sudo systemctl start <service_name>
  • Stop a service:
    sudo systemctl stop <service_name>
  • Restart a service:
    sudo systemctl restart <service_name>
  • Enable a service to start on boot:
    sudo systemctl enable <service_name>

6. Security Best Practices

6.1. Managing Firewalls

Amazon Linux uses iptables or firewalld for managing firewall rules.

  • Check firewall status:
    sudo systemctl status firewalld
  • Start/Stop/Restart the firewall:
    sudo systemctl start firewalld
    sudo systemctl stop firewalld
    sudo systemctl restart firewalld

6.2. Securing SSH Access

  • Change the default SSH port: Edit the SSH configuration file /etc/ssh/sshd_config and change the Port directive.

  • Disable root login via SSH: In the SSH configuration file, set PermitRootLogin no.

  • Restart SSH service:

    sudo systemctl restart sshd

7. Automating Tasks with Cron Jobs

7.1. Creating a Cron Job

Cron jobs are used to schedule tasks on the server.

crontab -e

Add the job in the following format:

* * * * * /path/to/script.sh

7.2. Viewing Scheduled Cron Jobs

crontab -l

7.3. Removing a Cron Job

crontab -r

8. Package Management with EPEL and Remi Repositories

8.1. Enabling EPEL Repository

EPEL (Extra Packages for Enterprise Linux) provides additional packages for Amazon Linux.

sudo amazon-linux-extras install epel -y

8.2. Enabling Remi Repository

The Remi repository is used to install PHP and other packages.

sudo amazon-linux-extras install epel
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

9. Managing System Backups

9.1. Creating a Backup with tar

The tar command is used to create compressed archives.

tar -czvf backup.tar.gz /path/to/directory

9.2. Restoring a Backup

tar -xzvf backup.tar.gz

10. Additional Resources


This documentation should serve as a comprehensive guide to managing an Amazon Linux server, covering essential tasks and best practices.


🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!