Table of contents
As a DevOps engineer working with AWS and Linux, having a solid understanding of command-line tools is essential for managing infrastructure, automating tasks, and troubleshooting issues.
In this comprehensive cheatsheet, we'll cover intermediate and expert-level AWS/Linux commands commonly used by DevOps engineers.
Each command will be described in detail, accompanied by examples and relevant documentation links.
AWS CLI Commands
AWS Configuration and Authentication
aws configure
: Configure AWS CLI with your access key, secret key, default region, and output format. Documentationaws sts get-caller-identity
: Retrieve the AWS account ID and IAM user details. This command is useful for verifying your authentication and authorization. Documentationaws ec2 describe-instances
: Retrieve information about EC2 instances in your AWS account. Documentationaws s3 ls
: List all S3 buckets in your AWS account. Documentationaws iam list-users
: List all IAM users in your AWS account. Documentation
EC2 Instance Management
aws ec2 run-instances
: Launch new EC2 instances based on specified parameters, such as instance type, AMI, security groups, and key pair. Documentationaws ec2 describe-instances
: Retrieve information about EC2 instances, including their status, public/private IP addresses, and tags. Documentationaws ec2 start-instances
: Start one or more stopped EC2 instances. Documentationaws ec2 stop-instances
: Stop one or more running EC2 instances. Documentationaws ec2 terminate-instances
: Terminate one or more EC2 instances. Exercise caution, as this action is irreversible. Documentation
S3 Bucket Operations
aws s3 cp
: Copy files and directories between local machine and S3 buckets, or between S3 buckets. Documentationaws s3 sync
: Synchronize files and directories between a local directory and an S3 bucket. This command is useful for incremental backups or data migrations. Documentationaws s3 rm
: Remove objects (files) from an S3 bucket. Documentationaws s3 ls
: List objects (files) in an S3 bucket. Documentationaws s3api put-bucket-policy
: Set an S3 bucket policy to define access permissions. Documentation
Networking and Security
aws ec2 create-security-group
: Create a security group to control inbound and outbound traffic for EC2 instances. Documentationaws ec2 authorize-security-group-ingress
: Add an inbound rule to a security group to allow specific traffic to EC2 instances. Documentationaws ec2 describe-security-groups
: Retrieve information about security groups in your AWS account. Documentationaws elbv2 create-load-balancer
: Create a load balancer for distributing traffic across multiple EC2 instances. Documentationaws route53 change-resource-record-sets
: Update DNS records in Amazon Route 53. This command is useful for managing domain names and routing traffic. Documentation
AWS CloudFormation
aws cloudformation create-stack
: Create a new AWS CloudFormation stack based on a template file. Documentationaws cloudformation describe-stack-events
: Retrieve events associated with a specific AWS CloudFormation stack. Documentationaws cloudformation update-stack
: Update an existing AWS CloudFormation stack by modifying the template or stack parameters. Documentationaws cloudformation delete-stack
: Delete an AWS CloudFormation stack and all associated resources. Documentationaws cloudformation validate-template
: Validate the syntax and structure of an AWS CloudFormation template file. Documentation
Linux Commands
File and Directory Operations
ls
: List files and directories in the current directory. Documentationcd
: Change the current directory. Usecd ..
to navigate to the parent directory. Documentationpwd
: Print the current working directory. Documentationmkdir
: Create a new directory. Documentationrm
: Remove files and directories. Use the-r
option to remove directories recursively. Documentation
Text Processing
grep
: Search for patterns in files or command output. Documentationsed
: Stream editor for filtering and transforming text. Documentationawk
: Pattern scanning and processing language for manipulating text files. Documentationcut
: Extract sections from lines of files. Documentationsort
: Sort lines of text files. Documentation
Process Management
ps
: Display information about active processes. Documentationtop
: Monitor system processes and resource usage in real-time. Documentationkill
: Send a signal to terminate or control processes. Documentationnohup
: Run a command that keeps running even after logging out. Documentationbg
/fg
: Control background and foreground jobs. Documentation
System Monitoring and Resource Management
df
: Display disk space usage of file systems. Documentationfree
: Display memory usage and available space. Documentationtop
: Monitor CPU and memory usage of processes in real-time. Documentationhtop
: Interactive process viewer with more advanced features. Documentationiotop
: Monitor I/O usage information of processes. Documentation
Network Configuration and Troubleshooting
ifconfig
: Display or configure network interfaces. Documentationping
: Send ICMP echo requests to a network host. Documentationnetstat
: Display network connections, routing tables, and interface statistics. Documentationnslookup
: Query DNS servers for DNS records. Documentationtraceroute
: Print the route packets take to network host. Documentation
Package Management
apt-get
: Command-line tool for package management in Debian-based systems. Documentationyum
: Package manager for RPM-based distributions like CentOS, Fedora, and Red Hat. Documentationdnf
: Next-generation package manager used in Fedora and CentOS 8+. Documentationpacman
: Package manager for Arch Linux and its derivatives. Documentationpip
: Package installer for Python. Documentation
User and Group Management
useradd
: Create a new user account. Documentationusermod
: Modify user account properties. Documentationuserdel
: Delete a user account. Documentationgroupadd
: Create a new group. Documentationgroupmod
: Modify group properties. Documentation
File Permissions
chmod
: Change file permissions. Documentationchown
: Change file owner and group. Documentationchgrp
: Change group ownership of files. Documentationlsattr
: List file attributes on a Linux second extended file system. Documentationchattr
: Change file attributes on a Linux second extended file system. Documentation
Archiving and Compression
tar
: Archive files together and create a tarball. Documentationgzip
: Compress files using gzip compression. Documentationgunzip
: Decompress files compressed with gzip. Documentationzip
: Package and compress files into a zip archive. Documentationunzip
: Extract files from a zip archive. Documentation
System Information
uname
: Print system information (kernel version, hostname, etc.). Documentationuptime
: Display system uptime and load average. Documentationdate
: Print or set the system date and time. Documentationwhoami
: Print the username of the current user. Documentationhostname
: Print or set the system hostname. Documentation
SSH and Remote Access
ssh
: Open a secure shell connection to a remote host. Documentationscp
: Securely copy files between local and remote hosts. Documentationrsync
: Efficiently synchronize files and directories between local and remote hosts. Documentationssh-keygen
: Generate SSH key pairs for secure authentication. Documentationssh-agent
: Manage SSH agents for storing private keys. Documentation
Conclusion
This extensive AWS/Linux commands cheatsheet covers a wide range of intermediate and expert-level commands that DevOps engineers use on a daily basis. Each command was described in detail, accompanied by relevant examples and documentation links for further reference. By familiarizing yourself with these commands, you'll be better equipped to manage AWS infrastructure, perform Linux system administration tasks, and streamline your DevOps workflows.
Remember, practice and hands-on experience are crucial for mastering these commands. Experiment with them in a controlled environment and explore their various options and arguments. The more you use them, the more proficient you'll become in leveraging their power for efficient and effective DevOps operations.
Happy command-line hacking!
Disclaimer: This article is intended as a reference guide and should not be considered as exhaustive or definitive. Command options, behaviors, and documentation may vary based on the specific Linux distribution, version, and AWS service configurations. Always refer to the official documentation for the most accurate and up-to-date information.