获取SSH登陆用户的IP地址

转自:https://blog.csdn.net/github_2011/article/details/60966976
一、找sshd进程
ps -ef|grep sshd
root      1693     1  0 Aug13 ?        00:00:00 /usr/sbin/sshd   #父进程号是1的是系统服务进程
root     12598  1693  2 14:59 ?        00:00:00 /usr/sbin/sshd   #有这个进程说明有SSHD远程客户登录
root     12638  1693  0 15:02 ?        00:00:00 /usr/sbin/sshd   #这是第二个登录用户
root     12633 12600  0 14:59 pts/0    00:00:00 grep sshd

二、根据登录上来的进程号找到用户进程
#ps -ef|grep 12598
root     12598  1693  0 14:59 ?        00:00:00 /usr/sbin/sshd
root     12600 12598  0 14:59 pts/0    00:00:00 -bash            #第一个用户,居然还是用root登录的。

#ps -ef|grep 12633
root     12638  1693  0 15:02 ?        00:00:00 /usr/sbin/sshd
root     12640 12638  0 15:02 pts/1    00:00:00 -bash            #第二个用户

三、根据bash进程的终端号pts/?来确定来源
[root@redhat root]# who -a|grep pts/1
root     + pts/1        Aug 14 15:02 00:03       12640 (192.168.0.123)   #登录来源IP192.168.0.123
[root@redhat root]# who -a|grep pts/0
root     + pts/0        Aug 14 14:59   .         12600 (192.168.0.123)   #登录来源IP192.168.0.123
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值