$24
Overview
In this assignment, you will be writing a systemd service and a corresponding timer. The service will run a shell script (provided by me) that writes the current system time to the file /root/cs447_647/pa2.log. The associated timer will cause this to run every 1 hour that the service is active. In addition, you will be creating a new user with the username “grading”, that has sudo access to all commands with the NOPASSWD option. Add my public key to the authorized_keys of this user, I will be using this account for grading this and future projects.
Submission
You will submit 2 files, the systemd service and the systemd timer (pa2.service, pa2.timer). You will also submit a text entry with the public IP address of your server. For grading, I will be connecting via SSH on port 2222 with the “grading” account, so make sure that account works properly with sudo.
To-Do
Create a new user with the username “grading”
adduser command
Add “grading” user to /etc/sudoers with visudo
Add NOPASSWD access for all commands
To test:
Run a command with sudo while logged into “grader” (i.e. sudo ls), make sure it doesn’t prompt you for a password
Create /usr/local/bin/pa2.sh, paste the following into it:
#!/bin/bash
mkdir -p /root/cs447_647
touch /root/cs447_647/pa2.log
echo "Hello world! The time is: $(date)" /root/cs447_647/pa2.log
Make script executable, chmod +x /usr/local/bin/pa2.sh
To test:
/usr/local/bin/pa2.sh
cat /root/cs447_647/pa2.log
Write systemd service to run /usr/local/bin/pa2.sh
sudo systemctl daemon-reload #after you make changes
Write systemd timer to run every hour
systemctl start pa2.timer
Useful Documentation
https://www.freedesktop.org/software/systemd/man/systemd.timer.html
https://www.freedesktop.org/software/systemd/man/systemd.service.html
https://linux.die.net/man/8/adduser
https://www.sudo.ws/man/1.8.15/sudoers.man.html
https://www.sudo.ws/man/1.8.17/visudo.man.html