-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanscript.sh
More file actions
36 lines (26 loc) · 843 Bytes
/
cleanscript.sh
File metadata and controls
36 lines (26 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Ensure the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Remove SSH authorized keys securely
if [[ -f ~/.ssh/authorized_keys ]]; then
rm -f ~/.ssh/authorized_keys
fi
# Clear user credentials and history
rm -f ~/.aws/credentials ~/.git-credentials ~/.bash_history
# Clean system logs and temporary files safely
find /var/log -type f -exec truncate -s 0 {} \;
rm -rf /tmp/* /var/tmp/*
# Remove a specific user account if it exists
if id "tempuser" &>/dev/null; then
deluser --remove-home tempuser
fi
# Lock the root account
passwd -l root
# Reset configuration files (example for Nginx)
if [[ -f /etc/nginx/nginx.conf ]]; then
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
fi
echo "System cleanup and security measures applied successfully."