Skip to main content

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.

2.2. Updating the System

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

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:
Example:

3.2. Searching for a Package

To search for a package, use:

3.3. Removing a Package

To remove a package, use the yum remove command:

4. Basic Commands

4.1. Navigating the File System

  • List files and directories:
  • Change directory:
  • Print the current working directory:

4.2. File Operations

  • Create a file:
  • View file contents:
  • Copy a file:
  • Move or rename a file:
  • Delete a file:

4.3. Managing Users and Groups

  • Add a new user:
  • Set a password for a user:
  • Delete a user:
  • Add a user to a group:

5. System Monitoring and Troubleshooting

5.1. System Resource Monitoring

  • Check system uptime:
  • View running processes:
  • Check memory usage:
  • Check disk usage:

5.2. Networking Commands

  • Check network interfaces:
  • Test network connectivity:
  • Display routing table:

5.3. Log Management

  • View system logs:
  • View SSH logs:
  • View Apache logs:

5.4. Service Management

  • Start a service:
  • Stop a service:
  • Restart a service:
  • Enable a service to start on boot:

6. Security Best Practices

6.1. Managing Firewalls

Amazon Linux uses iptables or firewalld for managing firewall rules.
  • Check firewall status:
  • Start/Stop/Restart the firewall:

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:

7. Automating Tasks with Cron Jobs

7.1. Creating a Cron Job

Cron jobs are used to schedule tasks on the server.
Add the job in the following format:

7.2. Viewing Scheduled Cron Jobs

7.3. Removing a Cron Job

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.

8.2. Enabling Remi Repository

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

9. Managing System Backups

9.1. Creating a Backup with tar

The tar command is used to create compressed archives.

9.2. Restoring a Backup

10. Additional Resources


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