三三世界-百宝箱

文章 分类 标签
132 9 250

公告

暂无站点公告

centos7查看登录日志,添加限制ip访问

三三 2022-03-10 2096 0条评论 Linux使用 centos登陆日志可登录的用户

首页 / 正文

centos7查看可登陆用户

cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1
cat /etc/passwd | grep   /bin/bash | cut -d : -f 1

查看登录成功的用户信息

last | less

查看登录失败的用户信息

lastb | less

查看登录日志

tail /var/log/secure

限制IP登录

vim /etc/hosts.deny

#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#

sshd:1.1.1.1:deny
sshd:21.122.198.1:deny

CentOS清除用户登录记录和命令历史方法

清除登陆系统成功的记录

[root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信息
[root@localhost root]# last //此时即查不到用户登录信息

清除登陆系统失败的记录

[root@localhost root]# echo > /var/log/btmp //此文件默认打开时乱码,可查到登陆失败信息
[root@localhost root]# lastb //查不到登陆失败信息

清除历史执行命令

[root@localhost root]# history -c //清空历史执行命令
[root@localhost root]# echo > ./.bash_history //或清空用户目录下的这个文件即可

导入空历史记录

[root@localhost root]# vi /root/history //新建记录文件
[root@localhost root]# history -c //清除记录 
[root@localhost root]# history -r /root/history.txt //导入记录 
[root@localhost root]# history //查询导入结果

example

[root@localhost root]# vi /root/history
[root@localhost root]# history -c 
[root@localhost root]# history -r /root/history.txt 
[root@localhost root]# history 
[root@localhost root]# echo > /var/log/wtmp  
[root@localhost root]# last
[root@localhost root]# echo > /var/log/btmp
[root@localhost root]# lastb 
[root@localhost root]# history -c 
[root@localhost root]# echo > ./.bash_history
[root@localhost root]# history

相关知识点

用户相关

centos7中所有用户都在文件/etc/passwd 中保存

管理员UID为0:系统的管理员用户。
系统用户UID为1~999
Linux系统为了避免因某个服务程序出现漏洞而被黑客提权至整台服务器,默认服务程序会有独立的系统用户负责运行,进而有效控制被破坏范围。

普通用户UID从1000开始:
是由管理员创建的用于日常工作的用户。

命令相关

grep 中-v为反向查找
cut 中-d 分割符号 -f为第几列

用户管理

useradd 增加用户
usermod 更改用户信息
groupadd增加组
userdel删除用户

评论(0)

当前没有评论,还不快来留下第一个脚印吧



最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年12月

1234567
891011121314
15161718192021
22232425262728
293031    

文章目录

上一张 下一张