π 1. SSH & Remote Access
ssh -i DevOps.pem ec2-user@ec2-x-x-x-x.compute-1.amazonaws.com
Purpose: Connect securely to an EC2 instance.
-
sshβ Secure Shell -
i DevOps.pemβ Use this private key for authentication -
ec2-user@hostβ Login user + EC2 hostname
π This is how you manually access EC2.
ssh user@host "command"
Purpose: Run a command on EC2 without logging in interactively.
Used in GitHub Actions to:
Verify connection
Create directories
Reload Nginx
Example:
ssh ec2-user@EC2_HOST "whoami && hostname"
ssh-keyscan -H EC2_HOST >> ~/.ssh/known_hosts
Purpose: Trust EC2βs SSH fingerprint automatically.
Prevents the βAre you sure you want to continue connecting?β prompt
Required for non-interactive CI/CD
We later made it safer:
ssh-keyscan -T 10 -H EC2_HOST >> ~/.ssh/known_hosts || true
π 2. File System Navigation & Inspection
pwd -- Print current directory path.
ls -- List files and directories
Variants:
ls -lβ permissions, owner, sizels -aβ include hidden files
cd directory - Change directory
Example:
cd DevOpsWeb
π 3. File & Directory Permissions (VERY IMPORTANT)
chmod - Change permissions
Examples:
chmod 755 directory
chmod 644 file
Meaning:
-
7= read + write + execute (owner) -
5= read + execute (group/others) -
4= read only
Used to:
Let Nginx read files
Prevent 403 Forbidden errors
chown - Change ownership
sudo chown -R ec2-user:nginx /home/ec2-user/DevOpsWeb
Owner β
ec2-userGroup β
nginx-Rβ recursive
π This allowed Nginx to read your deployed files.
sudo - Run command as root (admin)
Used for:
Installing packages
Editing system configs
Restarting services
π 4. Nginx (Web Server)
sudo yum install nginx -y - Install Nginx on Amazon Linux.
sudo systemctl start nginx - Start the Nginx service.
sudo systemctl enable nginx - Start Nginx automatically on reboot.
sudo systemctl status nginx - Check if Nginx is running and healthy.
sudo nginx -t - Test Nginx configuration for syntax errors.
π Always do this before reloading.
sudo systemctl reload nginx - Reload config without downtime.
π 5. Networking & Debugging
curl http://localhost
Test if the web server is responding **locally **on EC2.
If this works but browser doesnβt:
Security Group issue
Firewall issue
curl http://PUBLIC_IP - Test public access from EC2 itself.
lsof -i :80 - Check what is using port 80.
Used to confirm:
Nginx is listening
Apache was conflicting earlier
π¦ 6. Package Management
sudo yum install package -y - Install software non-interactively.
Examples:
sudo yum install httpd -y
sudo yum install docker -y
sudo yum remove httpd -y - Remove Apache to avoid port conflicts with Nginx.
π³ 7. Docker Basics (So Far)
docker run hello-world - Verify Docker installation.
docker build -t devops-website - Build Docker image from Dockerfile.
docker ps -a - List all containers (running + stopped).
docker exec -it container command - Run a command inside a running container.
Example:
docker exec -it devopsweb ls /usr/share/nginx/html
sudo usermod -aG docker ec2-user - Allow ec2-user to run Docker without sudo.
Requires logout/login to take effect.
8. Rsync (CI/CD Deployment)
rsync -avz --delete
Efficient file sync over SSH.
-aβ archive mode (permissions, timestamps)-vβ verbose-zβ compression--deleteβ remove files not present in source
Used to deploy:
WSL β GitHub β GitHub Actions β EC2
--exclude
Prevent syncing unwanted files:
--exclude='.git*'
--exclude='.github/'
--chmod
Force permissions on destination:
--chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r
This solved exit code 23 and permission issues.
π§ͺ 9. GitHub Actions / CI Commands
set -e - Exit immediately if a command fails.
set -eux
-eβ exit on error-uβ fail on undefined variables-xβ print commands (debugging)
Used to make pipelines fail loudly and clearly.
mkdir -p ~/.ssh - Create directory safely (no error if exists).
echo "$SECRET" > ~/.ssh/id_rsa - Write SSH key from GitHub Secrets.
Top comments (0)