# 查看VPS服务器是否被扫描 URL: https://chengjinfang.com/posts/2017/linux-auth/ Author: 程锦方 Date: 2017-10-25 Tags: #linux #note Summary: 通过认证日志查看 VPS 的 SSH 登录记录,统计成功和失败的来源地址。 ------------------------------------------------------------------------ auth日志地址 ``` vi /var/log/auth.log ``` ## 查看用密码登陆成功的IP地址及次数 ``` grep "Accepted password for root" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr | more ``` ## 查看用密码登陆失败的IP地址及次数 ``` grep "Failed password for root" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr | more ``` ## 更改默认端口 vi /etc/ssh/sshd_config ``` sed -i "s/原来的p .*/新的/g" /etc/ssh/sshd_config ``` ## 重启ssh ``` /etc/init.d/sshd restart #centos /etc/init.d/ssh restart #debian ``` ## 清除Linux的最近登录日志和Bash历史 last命令,对应的日志文件/var/log/wtmp; 成功登录用户 lastb命令,对应的日志文件/var/log/btmp; 尝试登录信息 lastlog命令,对应的日志文件/var/log/lastlog; 显示最近登录信息 清空日志文件: ```sh echo > /var/log/wtmp echo > /var/log/btmp echo > /var/log/lastlog ``` 清除Bash历史 你可以在执行命令时,指定Bash不保存执行历史: ```sh <空格>command ``` 在要执行命令前加一个空格。 清除当前登录session的历史: ```sh history -r ``` 清除所有历史: ```sh history -cw ``` [清除Linux的最近登录日志和Bash历史](http://topspeedsnail.com/clear-last-linux-login-log/) ------------------------------------------------------------------------ Site: https://chengjinfang.com/ · All Index: https://chengjinfang.com/all/ · RSS: https://chengjinfang.com/rss.xml