Linux on AWS EC2 Interview Questions and Answers for Cloud Engineers (50 Questions)
This page has 50 Linux interview questions with full answers, all from the view of a Linux server running on AWS EC2. General Linux interviews ask about commands. Cloud interviews ask how Linux behaves inside the cloud: disks that appear as NVMe, settings that come from metadata, and servers that are created by scripts.
1. An everyday example: a furnished rented flat
Why does Linux on EC2 need its own questions?
Most AWS servers run Linux. Many problems that look like "AWS problems" are really Linux problems on EC2: a disk not mounted after reboot, a full root volume, a script in user data that failed silently. Interviewers want to see that you can handle both sides.
Think of a furnished rented flat. The building (AWS) gives you walls, power and water (hardware, network, EBS). The flat comes with basic furniture (the AMI and its packages). A welcome note on the table tells you the Wi-Fi password (instance metadata and user data). You arrange the rest (users, packages, services and disks).
How to use this page
- Practise on a small Amazon Linux 2023 or Ubuntu instance in a test account.
- Run each command yourself and read the output aloud, as you would in an interview.
- Stop or terminate the instance afterwards so it does not cost money.
2. Fresher level questions
Start here if you are a fresher or have less than two years of experience. Try to answer each question aloud first. Then open it and compare.
Q1. What is the default login user on common EC2 Linux AMIs? Fresher
Each AMI family has its own default user, which receives your key pair's public key:
- Amazon Linux 2023 and Amazon Linux 2: ec2-user
- Ubuntu: ubuntu
- Debian: admin
- RHEL: ec2-user
- SUSE: ec2-user
Example: ssh -i shop-key.pem ec2-user@203.0.113.25.
If you use the wrong user name, you get "Permission denied (publickey)" even though the key is right. This is one of the most common beginner mistakes.
Q2. Which package manager does Amazon Linux 2023 use, and how is it different from Amazon Linux 2? Fresher
Amazon Linux 2023 uses dnf. Amazon Linux 2 used yum (dnf commands are similar).
Other differences in AL2023:
- Packages come from versioned repositories tied to a release, so updates are predictable.
- EPEL is not supported in the same way as on Amazon Linux 2, so some extra packages must come from other sources.
- It uses newer kernels and tools, and IMDSv2 is the default in its AMIs.
sudo dnf check-release-updateOutput:
A newer release of "Amazon Linux" is available.A newer AL2023 repository version exists. You choose when to move to it, for example after testing.
Q3. What is EC2 user data and where can you see what it did? Fresher
User data is a script or cloud-init configuration you give when launching an instance. cloud-init runs it during the first boot, as root.
Example: install Nginx and start it.
To see what happened:
sudo tail -5 /var/log/cloud-init-output.logOutput:
Complete!
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service
Cloud-init v. 22.2.2 finished at Fri, 20 Nov 2026 04:15:22 +0000. Up 41.20 secondsThe script finished and Nginx was enabled. If something failed, the error lines appear above this.
Q4. How do you read instance metadata, such as the instance ID, from inside an EC2 instance? Fresher
Use the Instance Metadata Service (IMDS) at 169.254.169.254. With IMDSv2, you first get a session token, then use it.
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-idOutput:
i-0a1b2c3d4e5f60001The instance ID was returned. The token is valid for 300 seconds here. Without the token, an IMDSv2-only instance returns 401 Unauthorized.
Q5. Why does a new EBS volume appear as /dev/nvme1n1 instead of /dev/sdf? Fresher
On Nitro-based instances, EBS volumes are exposed as NVMe block devices. Linux names them /dev/nvme0n1, /dev/nvme1n1 and so on, in the order they are detected.
The name you chose in the console, such as /dev/sdf, is kept as a hint in the device metadata, and Amazon Linux creates symlinks for it.
lsblk -o NAME,SIZE,SERIAL,MOUNTPOINTOutput:
NAME SIZE SERIAL MOUNTPOINT
nvme0n1 20G vol0a1b2c3d4e5f60001
└─nvme0n1p1 20G /
nvme1n1 100G vol0a1b2c3d4e5f60009The serial shows the EBS volume ID, so you can match each disk to the right volume.
Q6. How do you prepare and mount a new empty EBS volume on Linux? Fresher
- Check that the disk is empty:
sudo file -s /dev/nvme1n1shows "data" for an empty disk. - Create a file system:
sudo mkfs -t xfs /dev/nvme1n1. - Create a mount point and mount it:
sudo mkdir /data && sudo mount /dev/nvme1n1 /data. - Find its UUID with
sudo blkid, and add a line to /etc/fstab using the UUID with the nofail option. - Test fstab with
sudo umount /data && sudo mount -a.
Warning: never run mkfs on a disk that already has data. It erases everything.
Q7. Why should /etc/fstab entries for EBS volumes use UUID and nofail on EC2? Fresher
UUID: NVMe device names can change between reboots or instance types, so /dev/nvme1n1 might become /dev/nvme2n1. The UUID belongs to the file system and does not change.
nofail: if the volume is detached or missing, the instance still boots. Without nofail, a missing volume can stop the boot, and you cannot SSH in.
Example line:
UUID=8d2f4c1e-1111-2222-3333-444455556666 /data xfs defaults,nofail 0 2
Q8. What is instance store and what happens to its data? Fresher
Instance store is temporary disk physically attached to the host. Some instance types, such as those with a d in the name (for example m6id), include it.
- It is very fast and included in the instance price.
- Data is lost when the instance stops, hibernates or terminates, or if the disk fails. It survives a normal reboot.
Use it for caches, temporary files and scratch data, not for anything you cannot rebuild.
After a stop and start, you must format and mount it again, often with a boot script.
Q9. How do you check whether you are on an x86 or Arm (Graviton) EC2 instance? Fresher
uname -mOutput:
aarch64This is an Arm 64-bit CPU, so it is a Graviton instance. On Intel or AMD you would see x86_64.
Why it matters: binaries, Docker images and some packages must match the CPU architecture. A program built for x86_64 will fail on Graviton with "exec format error".
You can also see it in instance metadata or in the instance type name, where g means Graviton, such as t4g or m7g.
Q10. What is the SSM Agent and why is it important on EC2? Fresher
The SSM Agent is software on the instance that lets AWS Systems Manager manage it.
With it you can:
- Open a shell with Session Manager, without SSH keys or open port 22.
- Run commands on many instances with Run Command.
- Patch servers with Patch Manager and collect inventory.
It is preinstalled on many AWS AMIs, including Amazon Linux 2023 and recent Ubuntu AMIs. The instance also needs an IAM role with AmazonSSMManagedInstanceCore and network access to the Systems Manager endpoints.
Q11. How do you add SSH access for a second Linux user on an EC2 instance? Fresher
- Create the user:
sudo useradd -m priya. - Create the .ssh folder and authorized_keys file with the user's public key.
- Set strict permissions and ownership:
sudo install -d -m 700 -o priya -g priya /home/priya/.ssh
sudo install -m 600 -o priya -g priya priya.pub /home/priya/.ssh/authorized_keysThe folder is readable only by priya (700) and the key file only by priya (600). SSH refuses keys if these files are writable by others.
Never share the ec2-user private key between people. Each person gets their own key, or use Session Manager.
Q12. Where does an EC2 Linux instance get its time from? Fresher
EC2 instances can use the Amazon Time Sync Service, a time source available at the link-local address 169.254.169.123 (and an IPv6 address on Nitro instances). It is reachable without internet access.
Amazon Linux uses chrony and is configured for it by default.
chronyc sourcesOutput:
MS Name/IP address Stratum Poll Reach LastRx Last sample
^* 169.254.169.123 1 4 377 5 +12us[ +15us] +/- 402usThe star shows chrony is synced to the Amazon Time Sync Service, with a very small offset. Correct time matters for logs, TLS and AWS request signing.
Q13. What is the network interface name on a modern EC2 Linux instance, and what driver does it use? Fresher
On Nitro instances, the main interface usually appears as ens5 (Amazon Linux 2023) or with a similar predictable name, not always eth0.
It uses the Elastic Network Adapter (ENA) driver.
ethtool -i ens5 | head -2Output:
driver: ena
version: 2.13.0gEnhanced networking with ENA is active. Most current instance types require ENA support in the AMI, so custom AMIs must include the driver.
Q14. How do you install and use the AWS CLI on an EC2 instance without storing access keys? Fresher
- Attach an IAM role (instance profile) to the instance with the permissions it needs.
- Install the AWS CLI (Amazon Linux 2023 includes it).
- The CLI automatically gets temporary credentials from instance metadata.
aws sts get-caller-identity --query Arn --output textOutput:
arn:aws:sts::111122223333:assumed-role/shop-web-role/i-0a1b2c3d4e5f60001The CLI is using the role shop-web-role, through this instance. No keys are stored on disk, and the credentials rotate automatically.
Q15. How do you mount an Amazon EFS file system on Linux? Fresher
- Install the EFS mount helper: on Amazon Linux,
sudo dnf install -y amazon-efs-utils. - Make sure the EFS mount target's security group allows NFS (TCP 2049) from the instance's security group.
- Mount it with TLS:
sudo mount -t efs -o tls fs-0a1b2c3d4e5f60007:/ /mnt/shared
df -h /mnt/sharedOutput:
Filesystem Size Used Avail Use% Mounted on
127.0.0.1:/ 8.0E 12M 8.0E 1% /mnt/sharedEFS is mounted. The 8.0E size is normal because EFS grows automatically. The 127.0.0.1 source appears because TLS goes through a local stunnel.
Q16. What is the difference between rebooting and stopping an EC2 instance from the Linux point of view? Fresher
Reboot: the same instance restarts on the same host. EBS data, instance store data, private IP and public IP stay.
Stop and start: the instance may move to a different host.
- EBS data stays.
- Instance store data is lost.
- An auto-assigned public IPv4 address changes (an Elastic IP stays).
- The private IP stays.
Linux sees it as a normal shutdown and boot. Scripts that depend on instance store or a public IP must handle the change.
Q17. Is SELinux enabled on Amazon Linux 2023? Fresher
Yes. On Amazon Linux 2023, SELinux is enabled and runs in permissive mode by default. In permissive mode, it logs actions that the policy would deny, but does not block them.
getenforceOutput:
PermissiveSELinux is watching and logging, not enforcing. You can switch to enforcing mode for stronger security after testing that your applications work.
Denials are logged in the audit log, which you can read with ausearch.
3. Mid level questions
These questions check how you use the service in real projects. Interviewers expect the why, the how and one real example.
Q18. How do you grow a root EBS volume and its file system without downtime? Mid level
- Increase the volume size in EBS (console or
aws ec2 modify-volume). - On the instance, grow the partition, then the file system:
sudo growpart /dev/nvme0n1 1Output:
CHANGED: partition=1 start=24576 old: size=41918431 end=41943007 new: size=104832991 end=104857567sudo xfs_growfs -d /Output:
data blocks changed from 5239803 to 13104123 partition 1 now uses the new space, and the XFS root file system was grown online. For ext4, use sudo resize2fs /dev/nvme0n1p1.
Check with df -h /. Remember that EBS volumes can grow but not shrink.
Q19. How does user data behave on reboot, and how do you make a script run on every boot? Mid level
By default, a user data shell script runs only once, on the first boot of the instance. Rebooting or stopping and starting does not run it again.
Ways to run on every boot:
- Put the script in a cloud-init per-boot folder (/var/lib/cloud/scripts/per-boot/).
- Use a cloud-config with the right module frequency.
- Better for services: create a systemd unit that runs at boot.
To re-test user data on the same instance in a lab, you can clean the cloud-init state with sudo cloud-init clean and reboot, but in production, launch a new instance instead.
Q20. How do you protect IMDS from misuse by containers or SSRF attacks? Mid level
- Require IMDSv2 (HttpTokens=required). A simple GET from an SSRF bug cannot get the token, because IMDSv2 needs a PUT request with a special header.
- Set the hop limit. With a hop limit of 1, the token reply cannot cross the extra network hop into a container in bridge mode, so containers cannot use IMDS. Some AMIs, such as Amazon Linux 2023, set 2 so containers can reach it. Choose 1 if containers must not reach IMDS.
- Turn IMDS off if the instance does not need it.
aws ec2 modify-instance-metadata-options --instance-id i-0a1b2c3d4e5f60001 --http-tokens required --http-put-response-hop-limit 1Only IMDSv2 is allowed, and only processes on the host itself can reach it.
Q21. How do you match an NVMe device on Linux to its EBS volume ID? Mid level
The NVMe serial number contains the volume ID.
sudo nvme id-ctrl -v /dev/nvme1n1 | grep -E "^sn"Output:
sn : vol0a1b2c3d4e5f60009/dev/nvme1n1 is EBS volume vol-0a1b2c3d4e5f60009.
Amazon Linux also creates symlinks in /dev/disk/by-id/ that include the volume ID, and the ebsnvme-id tool shows the block device name you chose at attach time.
This is important before detaching or snapshotting the right disk.
Q22. How do you install and configure the CloudWatch agent on a Linux EC2 instance? Mid level
- Install the agent: on Amazon Linux 2023,
sudo dnf install -y amazon-cloudwatch-agent. - Attach an IAM role with CloudWatchAgentServerPolicy.
- Create a JSON config listing metrics (memory, disk) and log files (for example /var/log/nginx/error.log).
- Start it with the config:
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/config.json -s
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a statusOutput:
{ "status": "running", "configstatus": "configured" }The agent is running with your config. Memory and disk metrics now appear under the CWAgent namespace.
Q23. How do you add a swap file on an EC2 instance, and should you? Mid level
Many EC2 AMIs have no swap. A small swap file can prevent sudden out-of-memory kills during short spikes, but it is not a fix for too little memory.
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 && sudo chmod 600 /swapfile
sudo mkswap /swapfile && sudo swapon /swapfile && swapon --showOutput:
NAME TYPE SIZE USED PRIO
/swapfile file 2G 0B -2A 2 GiB swap file is active. Add it to /etc/fstab to keep it after reboot.
If the app uses swap all the time, choose a larger instance type instead, because swapping on EBS is slow.
Q24. What should you clean up on a Linux instance before creating an AMI from it? Mid level
Goal: every new instance from the AMI should start clean and unique.
- Remove temporary files, shell history and application logs.
- Remove any credentials, keys or .env files left on disk.
- Remove SSH host keys so new instances generate their own.
- Reset cloud-init state (
sudo cloud-init clean) so user data runs on new instances. - Remove machine-specific settings such as a fixed hostname or old IPs in config.
Better: build AMIs with an automated tool such as EC2 Image Builder or Packer from scripts, rather than snapshotting a hand-built server.
Q25. How do you mount an S3 bucket as a file system on Linux, and what are the limits? Mid level
Mountpoint for Amazon S3 is an AWS open-source client that mounts a bucket as a local folder.
mount-s3 shop-reports-prod /mnt/reports
ls /mnt/reports | head -2Output:
2026-11-19-sales.csv
2026-11-20-sales.csvobjects appear as files. It is designed for high-throughput reading and for writing new files sequentially.
Limits: it does not support all POSIX features, such as editing existing files in place, renaming directories or file locking. For a shared POSIX file system, use EFS or FSx instead.
Q26. How do you patch Linux on many EC2 instances in a controlled way? Mid level
- Use Systems Manager Patch Manager with patch baselines (which updates are approved, and after how many days).
- Group instances with patch groups or tags, for example Env=dev and Env=prod.
- Use maintenance windows: patch dev first, then prod a week later.
- For Auto Scaling groups, prefer baking a new patched AMI and doing an instance refresh, instead of patching running servers.
- Check compliance reports and reboot needs.
On Amazon Linux 2023, remember that updates follow repository versions, so you control when the whole fleet moves to a new release.
Q27. How do you raise the open-files limit for an application service on Linux? Mid level
Busy web servers and databases can hit "Too many open files".
For a systemd service, set the limit in the unit file, because /etc/security/limits.conf applies to login sessions, not systemd services.
sudo systemctl edit shop-apiOutput:
[Service]
LimitNOFILE=65536sudo systemctl restart shop-api && cat /proc/$(pidof -s node)/limits | grep "open files"Output:
Max open files 65536 65536 filesThe running process now has a 65536 open-file limit.
Q28. What is the MTU on EC2 networks and when does it cause problems? Mid level
Inside a VPC, many instance types support jumbo frames with an MTU of 9001 bytes. Traffic leaving the VPC, such as to the internet, a VPN or through an internet gateway, uses 1500 bytes or less.
Problems happen when large packets cannot be fragmented and Path MTU Discovery is blocked, for example when ICMP is blocked by a firewall. Symptoms: small requests work, large responses hang.
ip link show ens5 | grep -o "mtu [0-9]*"Output:
mtu 9001Fix: allow the ICMP messages needed for PMTUD in security groups and NACLs, or lower the MTU on interfaces that send traffic over VPNs.
Q29. How do you set a permanent hostname on an EC2 Linux instance? Mid level
By default, EC2 sets the hostname from the private IP or resource name, for example ip-10-20-1-15.ap-south-1.compute.internal, and cloud-init may reset it on boot.
To set your own:
sudo hostnamectl set-hostname web-prod-01Also tell cloud-init to keep it: set preserve_hostname: true in a cloud-init config file.
On the EC2 side, you can choose resource-based naming (the instance ID) instead of IP-based names in the subnet or launch settings.
Use tags and DNS for real identification. Hostnames are mainly for humans and logs.
Q30. How do you check whether an EC2 instance can reach the Systems Manager service? Mid level
When an instance does not appear in Fleet Manager, check:
- The agent:
sudo systemctl status amazon-ssm-agent. - The agent log: /var/log/amazon/ssm/amazon-ssm-agent.log for credential or network errors.
- The IAM role includes AmazonSSMManagedInstanceCore.
- Network: a route to the internet through NAT, or VPC interface endpoints for ssm, ssmmessages and ec2messages.
sudo grep -i "error" /var/log/amazon/ssm/amazon-ssm-agent.log | tail -1Output:
ERROR [CredentialRefresher] Retrieve credentials produced error: no EC2 instance role foundThe instance has no IAM role attached. Attach the role, and the agent registers within a few minutes.
Q31. How do you use EC2 Instance Connect from the command line? Mid level
EC2 Instance Connect pushes a temporary public key to the instance metadata for 60 seconds, and you connect with the matching private key. Access is controlled by IAM, and calls are logged in CloudTrail.
aws ec2-instance-connect ssh --instance-id i-0a1b2c3d4e5f60001 --os-user ec2-userOutput:
[ec2-user@ip-10-20-1-15 ~]$You logged in without a long-lived key on the server. For private instances, an EC2 Instance Connect Endpoint can be used, so you do not need a public IP or bastion.
The AMI must have the Instance Connect package (Amazon Linux and Ubuntu include it).
Q32. How do you run a command on many Linux instances at once without SSH? Mid level
Use Systems Manager Run Command with the AWS-RunShellScript document, targeting instances by tag.
aws ssm send-command --document-name AWS-RunShellScript --targets Key=tag:Role,Values=web --parameters 'commands=["df -h /"]' --query "Command.CommandId" --output textOutput:
0b1c2d3e-4f50-6172-8394-a5b6c7d8e9f0 The command was sent to every instance tagged Role=web. Read results with aws ssm list-command-invocations --command-id ... --details.
Benefits: no open SSH port, IAM-controlled, rate controls, and output can go to S3 or CloudWatch Logs.
Q33. How do you check if an EC2 instance's kernel has pending live patches or needs a reboot? Mid level
Amazon Linux 2023 supports kernel live patching, which applies some kernel security fixes without a reboot.
sudo dnf kernel-livepatch -y auto
sudo dnf needs-restarting -rOutput:
Core libraries or services have been updated since boot-up:
* kernel
Reboot is required to fully utilize these updates.A new kernel is installed but not running yet. Live patches cover only selected fixes, so you still need regular reboots or instance replacement.
On Ubuntu, a file /var/run/reboot-required shows the same need.
Q34. How do you attach a second network interface to an instance, and what must Linux do? Mid level
You can attach another ENI from a different subnet in the same AZ, for example for a management network.
On Amazon Linux 2023, the network tooling usually brings the new interface up automatically and adds policy routes, so replies leave through the correct interface.
On some other distributions you must configure it yourself, otherwise traffic that arrives on the second interface may leave through the first one and be dropped (asymmetric routing).
Check with ip addr, ip rule and ip route show table all.
Q47. How do you read the instance's own tags from inside Linux? Mid level
Instance tags are not in metadata by default. First allow tags in instance metadata (InstanceMetadataTags=enabled in the metadata options or launch template).
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/tags/instance/EnvOutput:
prodThe instance knows it is tagged Env=prod, without calling the EC2 API or needing IAM permissions.
Use case: one AMI that configures itself differently for dev and prod at boot. Note that tag keys with spaces or some special characters cannot be read this way.
4. Senior level and scenario questions
These questions check design thinking and troubleshooting. Think aloud. Say what you check first, what you change, and how you prevent it next time.
Q35. You launched 20 instances with user data, but the app is missing on 3 of them. How do you investigate? Senior
- Compare /var/log/cloud-init-output.log and /var/log/cloud-init.log on a good and a bad instance.
- Common causes: package repositories or S3 not reachable at boot (NAT or endpoints not ready), a script that does not stop on errors and skips steps, a race with another service, or rate limits when 20 servers download from the same source.
- Make the script robust:
set -euo pipefail, retries with backoff for downloads, and clear log lines. - Signal success: use a health check or cfn-signal, so failed instances are replaced automatically.
Better long-term: bake software into the AMI or container and keep user data small.
Q36. An EBS data volume stopped mounting after the team changed the instance type. Why, and how do you prevent it? Senior
Changing the instance type, for example from an older Xen type to a Nitro type, can change device names from /dev/xvdf to /dev/nvme1n1. If /etc/fstab used the device name, the mount fails.
Without nofail, the instance may even fail to boot.
Prevention:
- Use UUID or LABEL in fstab, with nofail.
- Make sure the AMI has the NVMe and ENA drivers before moving to Nitro.
- Test instance type changes on a copy first.
Recovery: use the EC2 serial console or attach the root volume to a rescue instance and fix fstab.
Q37. How would you build a hardened Linux AMI for your company? Senior
- Start from an official, current AMI (Amazon Linux 2023 or Ubuntu).
- Use EC2 Image Builder or Packer with versioned scripts in Git.
- Apply a hardening standard, such as CIS benchmarks: remove unused packages, set SSH options, enable auditd, set file permissions.
- Install agents: SSM Agent, CloudWatch agent and security tools.
- Require IMDSv2 in launch templates.
- Scan the image with Amazon Inspector and run tests before sharing.
- Share it to accounts through AWS Organizations, and deprecate old AMIs on a schedule.
Q38. Developers want root access on production EC2 instances to debug. How do you handle it? Senior
- Do not give permanent root or shared keys.
- Use Session Manager with IAM permissions per team, session logging to S3 or CloudWatch Logs, and run-as users with limited sudo rules.
- Grant elevated access only for a limited time, through an approval process or IAM Identity Center permission sets.
- Give read-only debug paths: centralised logs, metrics, traces and Run Command documents for common checks.
- Treat servers as replaceable: if someone made manual changes, rebuild the instance from the AMI afterwards.
This keeps an audit trail and reduces risk.
Q39. A Linux instance in a private subnet cannot install packages with dnf. What do you check? Senior
- Amazon Linux 2023 repositories are hosted on S3-backed endpoints. A private subnet needs a NAT gateway route, or an S3 gateway endpoint whose policy allows the Amazon Linux repository buckets.
- Security group and NACL outbound rules must allow HTTPS.
- DNS resolution must work (enableDnsSupport on the VPC).
- A proxy setting may be needed in /etc/dnf/dnf.conf in corporate networks.
sudo dnf makecacheOutput:
Error: Failed to download metadata for repo 'amazonlinux': Cannot download repomd.xml: Curl error (28): Timeout was reachedA network timeout, not a package problem. Check routes and endpoints first.
Q40. How do you design Linux log handling for an Auto Scaling fleet where instances come and go? Senior
Local logs disappear when an instance is terminated, so:
- Send application and system logs to CloudWatch Logs with the CloudWatch agent, or to another central system.
- Write logs to stdout or files with a clear format (JSON is easiest to query).
- Include the instance ID, version and request ID in each line.
- Set retention per log group, and export old logs to S3 if needed.
- Keep local logrotate settings so the root disk never fills.
- Use lifecycle hooks to flush logs before termination.
Q41. An instance must keep a fixed private IP and fixed public IP even if it is replaced. How do you design it? Senior
- Private IP: create a separate ENI with a fixed private IP, and attach it to the replacement instance. Or put the service behind an NLB, which gives a stable address.
- Public IP: use an Elastic IP and reassociate it to the new instance, or let the NLB own the Elastic IPs.
- Automate the move with a lifecycle hook or a boot script that attaches the ENI or Elastic IP.
Better: avoid IP dependencies by using DNS names in Route 53, so clients follow changes automatically.
Q42. How do you troubleshoot slow disk performance on a Linux EC2 instance with EBS? Senior
- Measure on Linux:
iostat -xz 1shows await (latency), %util and queue size per device. - Compare with the EBS volume's provisioned IOPS and throughput, and the instance's EBS bandwidth limit. Small instances have lower EBS limits.
- Check CloudWatch EBS metrics: VolumeQueueLength, and for gp2 the BurstBalance.
- Newly restored volumes from snapshots are slow on first read of each block, unless Fast Snapshot Restore was used or you pre-read the volume.
Fixes: gp3 with higher IOPS, a larger instance with more EBS bandwidth, RAID 0 across volumes, or caching.
Q43. How do you make a Linux web server on EC2 ready for Graviton migration? Senior
- Check that all software has arm64 builds: runtime, packages, agents and any compiled native libraries.
- Build multi-architecture container images, or build the app on an arm64 build agent.
- Launch a test Graviton instance (for example m7g) from an arm64 AMI.
- Run functional and load tests, and compare latency and cost per request.
- Roll out gradually: add Graviton instances to the Auto Scaling group with a mixed instances policy, then increase their share.
Most interpreted languages (Python, Node.js, Java) move easily. Problems usually come from old native binaries.
Q44. A security scan found that an EC2 instance still allows IMDSv1. How do you fix the whole fleet safely? Senior
- Find all instances: use the EC2 console filter, AWS Config rule ec2-imdsv2-check, or Security Hub findings.
- Check the CloudWatch metric MetadataNoToken to see whether anything still calls IMDS without a token.
- Update old SDKs and agents that only use IMDSv1.
- Set HttpTokens=required on running instances, and in all launch templates and AMIs.
- Set the account-level default for new instances to IMDSv2 only, and use an SCP or Config rule to block launches without it.
Q45. How do you recover a Linux instance where someone ran chmod -R 777 on /etc? Senior
SSH will refuse to work, sudo will complain, and some services will fail, because many files in /etc need strict permissions.
Options:
- If the instance is replaceable: terminate it and launch a new one from the AMI. This is the fastest and cleanest.
- If it must be saved: stop it, attach the root volume to a rescue instance, and restore permissions, for example with
rpm --setpermsfor all packages on RPM-based systems, then fix files not owned by packages, such as SSH keys, by hand. - Or use the EC2 serial console if a password user exists.
Prevention: least privilege, change review and immutable servers.
Q46. How would you run a stateful Linux service, like a self-managed database, on EC2 safely? Senior
- Use EBS gp3 or io2 volumes, with the data on a separate volume from the OS.
- Take regular EBS snapshots with consistent database backups (flush or use the database's backup tool), using AWS Backup or Data Lifecycle Manager.
- Use instance types with enough EBS bandwidth and memory.
- Plan high availability: replication to a second instance in another AZ with automatic failover.
- Monitor disk, replication lag and backup success.
- Test restores.
Also ask whether a managed service like RDS would remove most of this work.
Q48. A team wants to cut cost by shrinking a 500 GiB root EBS volume to 50 GiB. How do you do it? Senior
EBS volumes cannot be shrunk in place. You must copy the data to a smaller volume.
Steps:
- Take a snapshot of the current volume as a safety copy.
- Create a new 50 GiB volume, attach it to a helper instance with the old volume, and create matching partitions and a file system.
- Copy the data with rsync, keeping permissions, ACLs and SELinux labels.
- Update the boot loader and fstab for the new UUIDs, and test boot on a copy.
For root volumes this is risky, so a cleaner option is to build a new instance from a fresh AMI with a 50 GiB root volume and move the application and data to it.
Q49. How do you collect evidence from a Linux EC2 instance you suspect is compromised? Senior
Preserve evidence before you change anything.
- Isolate it: replace its security group with one that allows no traffic (or only forensic access), and detach it from the load balancer and Auto Scaling group.
- Take EBS snapshots of all volumes, and tag them with the case ID.
- Capture volatile data if your process allows: running processes, network connections and memory, using approved tools.
- Turn on termination protection and do not reboot, because memory evidence would be lost.
- Analyse copies of the volumes on a separate forensic instance in an isolated account.
GuardDuty findings and CloudTrail help build the timeline.
Q50. An engineer who had the shared EC2 key pair left the company. How do you rotate access on many running instances? Senior
Changing the key pair in the EC2 console does not change keys on running instances. The public key lives in each user's authorized_keys file.
Steps:
- Generate a new key, and use Systems Manager Run Command to add the new public key and remove the old one from authorized_keys on all instances.
- Verify that you can log in with the new key before removing the old one everywhere.
- Update launch templates to use the new key pair.
- Better: stop using shared keys. Move to Session Manager or EC2 Instance Connect with IAM, so removing the person's IAM access removes server access.
5. Frequently asked questions
Amazon Linux 2023 or Ubuntu: which should I learn?
Learn both at a basic level. Amazon Linux 2023 uses dnf and is common in AWS-heavy companies. Ubuntu uses apt and is common in startups and container hosts. The cloud ideas are the same.
Do I still need SSH skills if Session Manager exists?
Yes. Many companies still use SSH, and you must understand keys and permissions. But also know Session Manager, because secure companies prefer it.
What should I build to practise?
Launch an instance with a user data script that installs Nginx, add a second EBS volume, mount it with UUID and nofail, grow it, and send logs to CloudWatch with the agent.
6. Quick revision
- User data runs once on first boot by default. Its output is in /var/log/cloud-init-output.log.
- IMDSv2 needs a token first: PUT, then GET with the token header.
- EBS volumes appear as /dev/nvme*n1 on Nitro instances. Mount by UUID with nofail.
- Growing a disk: modify the volume, growpart, then xfs_growfs or resize2fs.
- Time on EC2 comes from the Amazon Time Sync Service through chrony.
7. Related chapters
- Linux Complete Interview Pack 1: 300 Linux Interview Questions and Answers for Beginner, Mid and Senior Level
- Linux Complete Interview Pack 3: Linux Interview Questions Commonly Asked at TCS, Infosys, Accenture, Wipro, Amazon, Google and Red Hat, with RHCSA-Style Tasks
- Linux Complete Interview Pack 2: 150 Shell Scripting Interview Questions and Answers with Coding Exercises
- AWS EC2, EBS, Auto Scaling and Load Balancer Interview Questions and Answers (50 Questions)
- How to Add, Format and Mount an EBS Volume on EC2 (fstab)
- What Is Amazon EC2 and How Does It Work
This page is one part of a 1000-question AWS interview set. Open the full list here: All 1000 AWS interview questions.