Linux Assignment
We can setup the SMTP server using Postfix
update the package list to ensure you have the latest information:
sudo apt-get update # For Debian/Ubuntu
sudo apt-get install postfix mailutils # For Debian/Ubuntu
The first part of the Postfix installation is a text-base user interface. Use you keyboard to select Internet Site for the type of mail configuration. On the next screen, enter the domain name of your server. Please note that this doesn’t have any impact on your ability to send mail from Gmail, so if you don’t have a domain name, that’s okay.
Configuration file that is located at /etc/postfix/main.cf
sudo nano /etc/postfix/main.cf
Add the following lines to the main.cf file:
relayhost = [smtp.gmail.com]:587
myhostname = your_hostname
# Location of sasl_passwd we saved
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
# Enables SASL authentication for postfix
smtp_sasl_auth_enable = yes
smtp_tls_security_level = encrypt
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
Create a the file /etc/postfix/sasl/sasl_passwd and add your Gmail address and app password to it like this:
[smtp.gmail.com]:587 mailid@example.com:qodjkozoaqdmyjjj
sudo postmap /etc/postfix/sasl/sasl_passwd
To start Postfix,
sudo systemctl start postfix
To restart Postfix,
sudo systemctl restart postfix
To stop Postfix
sudo systemctl stop postfix
Ensure that Postfix is enabled to start at boot:
sudo systemctl enable postfix
sendmail mailid@example.com
To: mailid@example.com
Subject: Test mail #1
This is just a test email
.
sudo adduser <username>
For example,
sudo adduser prassana
groups <username>
sudo deluser <username> sudo
5. To verify user does not have sudo privileges you can try to run any command with sudo for example
sudo ls
Q3) Configure your system in such a way that when a user type and executes a describe command from anywhere of the system it must list all the files and folders of the user's current directory.
nano ~/.bashrc
alias describe="ls"
source ~/.bashrc
Q4)U sers can put a compressed file at any path of the linux file system. The name of the file will be research and the extension will be of compression type, example for gzip type extension will be .gz. You have to find the file and check the compression type and uncompress it.
find / -name "research.gz" -exec gunzip {} \;
Q5) Configure your system in such a way that any user of your system creates a file then there should not be permission to do any activity in that file.
umask 077
2. This will ensure that when any user creates a file, the default permissions for others will be restricted, and they won't have any access to the file.
source ~/.bashrc
touch newfile.txt
5. The permissions for myfile.txt will be such that only the file owner will have read and write access, while all others will have no permissions. The file owner can still modify its permissions if needed.
Q6) Create a service with the name showtime , after starting the service, every minute it should print the current time in a file in the user home directory.
To create a systemd service named "showtime" that prints the current time to a file in the user's home directory every minute, follow these steps:
#!/bin/bash
while true; do
date | awk '{print $4}' >> "$HOME/showtime.txt"
sleep 60
done
chmod +x /home/<username>/showtime.sh
[Unit]
Description=Showtime Service
[Service]
Type=simple
ExecStart=/home/showtime.sh
User=<username>
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable showtime.service
sudo systemctl start showtime.service