Last update at :2024-06-22,Edit by888u
In order to ensure the security of our VPS, we will set up email reminders for anyone who logs in via SSH. This means that even after we use SSH to log in to the VPS remote link, there will be an email reminder reporting which IP is currently logged into our VPS. system. Snail has seen articles like this that were not compiled before. Now they are compiled for three commonly used systems: CentOS/Ubuntu/Debian. After testing, they can all be used.
First, Ubuntu/Debian system environment
A - Log in to SSH to upgrade the current system environment
apt-get update
B - Edit the ~/.bashrc file in the root directory and add the following script at the bottom
IP=\\”$(echo $SSH_CONNECTION | cut -d \\” \\” -f 1)\\”HOSTNAME=$(hostname)NOW=$(date +\\”%e %b % Y, %a %r\\")echo \\'Someone from \\'$IP\\' logged into \\'$HOSTNAME\\' on \\'$NOW\\'.\\' | mail - s \\'SSH Login Notification\\' YOUR_EMAIL_ADDRESS
Change YOUR_EMAIL_ADDRESS to the email account we need to accept.
C – reboot to restart the VPS, and then log in again to see if we can see the mailbox receiving emails
Second, CentOS system
A - Log in to SSH and edit the ~/.bash_profile file
B -Add files
IP=\\”$(echo $SSH_CONNECTION | cut -d \\” \\” -f 1)\\”HOSTNAME=$(hostname)NOW=$(date +\\”%e %b % Y, %a %r\\")echo \\'Someone from \\'$IP\\' logged into \\'$HOSTNAME\\' on \\'$NOW\\'.\\' | mail - s \\'SSH Login Notification\\' YOUR_EMAIL_ADDRESS
Change YOUR_EMAIL_ADDRESS to the email account we need to accept.
PS: If there is no prompt to send emails after logging in, and the -bash: mail: command not found error message appears, how to solve it?
apt-get install mailutils #Ubuntu/Debian system environment
yum install mailx #CentOS system
Install the components corresponding to the system and then restart to realize email reminders for SSH login users.
In summary, security must be paid attention to when using a VPS. If we firmly believe in the security of the password or the security of the local system, it is best to send an email reminder in case someone else logs in or cracks our password and the VPS is safe. Hidden danger.
Recommended reading:
Set Putty SSH to use the key to log in to the Linux VPS host
Xshell sets key login to ensure Linux VPS and server are more secure
Recommended site search: How to register a domain name, asp host registration-free space, vps foreign server, US virtual host purchase, cheap virtual host, jsp host, personal domain name registration, how long does it take to register a website, private server rental,
发表评论