Skip to content

Instantly share code, notes, and snippets.

@SkymeFactor
Last active November 16, 2020 15:13
Show Gist options
  • Save SkymeFactor/c2c3ebe4f9f797998f81bbfdcc7e96a1 to your computer and use it in GitHub Desktop.
Save SkymeFactor/c2c3ebe4f9f797998f81bbfdcc7e96a1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# In order to delete all the mess created by this script
# just run it with "del" as a parameter
if [ "$1" != "del" ]; then
# 1. List all users and their id's into work3.log
for user in $(cat /etc/passwd | awk -F ":" '{print $1}'); do
echo -e "user \"${user}\"\thas id $(id -u $user)" >> work3.log
done
# 2. Add the last password change date for root into the end of work3.log
echo $(chage -l root | grep "Last" | awk -F ": " '{print $2}') >> work3.log
# 3. Add the list of all groups in system divided by commas
cat /etc/group | awk -F ":" '{printf("%s, ", $1)} END {print ""}' >> work3.log
# 4. Make the file that will be created by default at a new user home folder
echo "Be careful!" > /etc/skel/readme.txt
# 5. Add a new user u1 with password 12345678
useradd -m -p $(openssl passwd -1 -stdin <<< 12345678) u1
# 6. Add a new group g1
groupadd g1
# 7. Add user u1 to group g1
usermod -aG g1 u1
# 8. Add the name, uid and groups of u1 to the end of work3.log
echo -e "user \"u1\"\thas id $(id -u "u1")" >> work3.log
echo "groups of $(groups u1)" >> work3.log
# 9. Add $USER to g1 group
usermod -aG g1 $USER
# 10. Add all g1 users into the end of work3.log
grep g1 /etc/group | awk -F ":" '{print $NF}' >> work3.log
# 11. Run mc after login and die after logout for u1
echo "/usr/bin/mc" >> /home/u1/.bash_profile
echo "/usr/bin/pkill -KILL -u u1" >> /home/u1/.bash_profile
# 12. Add a new user u2 with password 87654321
useradd -m -p $(openssl passwd -1 -stdin <<< 87654321) u2
# 13. Create /home/test13/ and copy work3.log into it
mkdir /home/test13/
cp work3.log /home/test13/work3-1.log
cp work3.log /home/test13/work3-2.log
# 14. only u1 and u2 can read /home/test13/, only u1 can write
chown -R u1 /home/test13/
chgrp -R u2 /home/test13/
chmod 750 /home/test13/
# 15. Make /home/test14/ with exclusive delete permission for u1
mkdir /home/test14/
chown u1 /home/test14/
chgrp u2 /home/test14/
chmod 1777 /home/test14/
# 16. Copy nano to /home/test14/ and let anyone change files in /home/test13/ by it
cp /bin/nano /home/test14/
chown u1 /home/test14/nano
chmod 4777 /home/test14/nano
# 17. Add /home/test15/ and a secret_file in it, make this file invisible
mkdir /home/test15/
echo "Be careful!" > /home/test15/secret_file
chmod a-r /home/test15/
else
rm work3.log
rm /etc/skel/readme.txt
userdel u1
userdel u2
groupdel g1
rm -r /home/u1
rm -r /home/u2
rm -r /home/test13/
rm -r /home/test14/
rm -r /home/test15/
fi
@SkymeFactor
Copy link
Author

@AlexTalker, что к защите готовить?

@AlexTalker
Copy link

К защите изучите как задавать shell по-умолчанию пользователю и для чего это может быть полезно.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment