1. Create a directory and add a file in that directory.
1. Launched ubuntu instance.
2. SSH to an instance using EC2 instance connect.
3. Created a directory using command : mkdir file1
using the ls command listed.
4. Change the path using cd command to create a file in that directory.
5. Using the touch command create a file.
2. Create a new user and give sudo privileges.
1. Created the shyam user using adduser command
sudo adduser shyam
Once we create the user asks for password.
Provided the password.
2. For sudo privileges
sudo usermod -aG group.name username
Run this command : sudo usermod -aG sudo shyam
Check that user belongs to sudo group using : groups shyam
Verify sudo access : with user : su - shyam
sudo whoami
sudo apt install nginx
3. Set file permissions and ownership for the created user and
access the file with the user.
Created a file named subfile in the file1 directory in task 1.
Lets add sample text in the subfile using : vi subfile
And verify using command : cat subfile
Giving the full ownership of file subfile to the user shyam
sudo chown shyam:shyam subfile
Permissions using : sudo chmod 600 subfile
Accessing the file as user shyam which we have given the permissions for.
su - shyam
sudo cat /home/ubuntu/file1/subfile
4. Use commands like top, htop, ps, free, and vmstat to monitor
processes and memory usage of the system.
top :
This is for system monitoring.
here in this 1 process is running and 105 are not currently running means not using CPU
htop :
htop command is an interactive process viewer, similar to the top command, but with a
more user-friendly interface.
ps : this command is used to display currently running processes.
For the current shell
To view all running processes : ps -A or ps -e
free : displays the total and free memory usage including both RAM and Swap.
free -b for info in bytes
free -k in kilobytes
free -m in megabytes
vmstat : virtual memory statistics : built in utility for monitoring in liunx
8. Generate SSH keys for the user and configure passwordless
login.
1. In client server create ssh key using
Command : ssh-keygen -t rsa -b 4096
This command will generate two keys : id_rsa & id_rsa.pub
2. We need copy this in remote server using : ssh-copy-id username@server_ip
3. Connect remote server from client server : ssh username@server_ip
5. Write a script to Monitor the disk usage and send an alert if
usage exceeds 50%, Schedule this script using cron to run every
hour.
1. We need to update the packages and install the msmtp mailutilis using :
sudo apt update
sudo apt install msmtp msmtp-mta mailutils
2. In Gmail we need to enable two step verification if not enabled.
Create the app password and copy that six digit password.
3. Add the following details in below file :
vi ~/.msmtprc
Save and exit.
Set the permissions : chmod 600 ~/.msmtprc
4. echo "Test mail" | mail -s "Test subject" [email protected]
6. Add the following script :
vi alert.sh
Make it executable : chmod +x alert.sh
Check manually by running : ./alert.sh
7.
crontab -e
0 * * * * /home/ubuntu/alert.sh
Save and exit.
9. Check system uptime and load average.
Going left to right:
The first value depicts the average load on the CPU for the last minute.
The second gives us the average load for the last 5-minute interval.
The third value gives us the 15-minute average load
7.What is Crontab? Get the system logs and store the backup of
that file using cron.
Crontab is a powerful utility used for Task Scheduling and Task Automation.
1. Create a backup.sh file
2. Open an editor with that file add copy command
Save and exit.
3. Make it executable using : sudo chmod +x /home/ubuntu/logs_backup.sh
4. crontab -e
0 14 * * * /home/ubuntu/logs_backup.sh
Save and exit.
5. Check by running manually using below command :
./logs_backup.sh
6. Create a python script that needs to run as a background service
on boot Using systemd.
Create the directory for script.
Add the following script in the path : sudo vi my_script.py
Making it executable using : sudo chmod +x /opt/my_service/my_script.py
Add the following systemd script in the mentioned path
sudo vi /etc/systemd/system/my_script.service
Reload, enable and start the service :
Check the status using : sudo systemctl status my_script.service
cat /var/log/my_service.log
10. What is LVM ?
LVM, provides a method of allocating and managing space on mass-storage devices that is
more advanced and flexible than the traditional method of partitioning storage volumes.
11. Installing, updating, and removing software packages
Installing : sudo apt install <packagen.name>
sudo apt install curl
Check : curl –version
Updating : sudo apt update
Removing : sudo apt remove curl
Check : curl –version
12. Setting up and managing swap space
Creating the swipe file using : sudo fallocate -l 2G /swapfile
Check using : ls -lh /swapfile
Set the permissions : sudo chmod 600 /swapfile
Format the file as swap : sudo mkswap /swapfile
enable the swap file : sudo swapon /swapfile
verify that the swap is available by : sudo swapon --show and free -h
swap file does not persist after a restart by default. to make the changes permanent add it to
/etc/fstab:
We can use echo or vi editor to add this line : swapfile none swap sw 0 0