Exploring the behavior analysis of Linux users
在当今数字化的时代,人们已经习惯于用电脑进行工作和娱乐,而Linux系统在其中扮演着重要的角色。Linux操作系统由于其安全性、开源性以及可定制性等优点,被广泛地应用于各个领域。然而,作为一种特殊的操作系统,Linux用户的行为与Windows或Mac用户的行为有所不同。本文将深入探讨Linux用户的行为特点,为大家揭开Linux操作系统的神秘面纱。
如果您在管理Linux服务器,最好准备好使用用于检查用户活动的多个命令——用户何时登录及登录频率、属于哪些用户组、耗用多少磁盘空间、运行什么命令、占用多少磁盘空间、是否在阅读邮件等。
本文小编将为大家介绍了在Linux下有可以命令可以帮助您了解用户有哪些、查看他们在如何工作、以及分析用户的详细操控行为等。
finger命令
finger是获取用户个人资料的一个便捷命令。它使您可以查看谁已登录或专注于单个用户,以查看上一次登录、他们从何处登录、闲置时间有多久(自运行命令以来有多久)等。在该命令中, 我们查看用户nemo。
$ finger nemo Login: nemo Name: Nemo Demo Directory: /home/nemo Shell: /bin/bash On since Fri Jun 19 12:58 (EDT) on pts/1 from 192.168.0.6 7 minutes 47 seconds idle New mail received Wed Jun 17 18:31 2020 (EDT) Unread since Sat Jun 13 18:03 2020 (EDT) No Plan.
我们可以看到nemo的全名、主目录和外壳,还可以看到nemo的最新登录和电子邮件活动。仅在/etc/passwd文件中的全名字段中定义了办公室、办公室电话和家庭电话号码,这些信息才包括在内。比如说:
nemo:x:1001:1001:Nemo Demo,11,540-222-2222,540-333-3333:/home/nemo:/bin/bash).
上面的输出还表明nemo没有“计划”,但这只是意味着该用户没有创建.plan文件、并将一些文本放入其中。这并不罕见。
如果没有参数,finger将以如下所示的格式显示当前登录列表。您可以看到他们何时登录、从哪个IP地址登录、使用中的伪终端(比如pts/1)以及闲置了多久。
$ finger Login Name Tty Idle Login Time Office Office Phone nemo Nemo Demo pts/1 1:24 Jun 19 12:58 (192.168.0.6) shs Sandra Henry-Stocker pts/0 Jun 19 12:57 (192.168.0.60
w命令
w命令也以一份格式清晰的列表显示了目前活动的用户,包括闲置时间、用户最近运行了什么命令。它还在最上面一行显示系统已运行了多久,并提供负载平均数字,表明系统有多忙碌。在这里,系统基本上处于闲置状态。
$ w 14:23:19 up 1 day, 20:24, 2 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT shs pts/0 192.168.0.6 12:57 0.00s 0.14s 0.01s w nemo pts/1 192.168.0.6 12:58 1:24m 0.03s 0.03s -bash
id命令
如果使用id命令,您可以查看用户的数值ID和用户组ID以及该用户是哪些用户组的成员。这些信息从/etc/passwd文件和/etc/group文件获取而来。没有参数的id报告您帐户的信息。
$ id uid=1000(shs) gid=1000(shs) groups=1000(shs),4(adm),11(admin),24(cdrom),27(sudo),30(dip),46(plugdev),118(lpadmin),128(sambashare),500(devops) $ id nemo uid=1001(nemo) gid=1001(nemo) groups=1001(nemo),16(fish) auth.log
您可以使用grep之类的命令从/var/log/auth.log文件获取信息。为了使用auth.log数据显示最近登录活动,您可以运行这样的命令:
$ grep "New session" /var/log/auth.log | awk '{print $1,$2,$3,$11}' | tail -5 Jun 17 17:22:38 shs. Jun 17 17:58:43 gdm. Jun 17 18:09:58 shs. Jun 19 12:57:36 shs. Jun 19 12:58:44 nemo.
last命令
last命令可能最擅长查看所有用户或某一个用户的最近登录。记住一点:last首先显示最近的活动,因为这是大多数管理员最感兴趣的信息。
$ last | head -5 nemo pts/1 192.168.0.6 Fri Jun 19 12:58 still logged in shs pts/0 192.168.0.6 Fri Jun 19 12:57 still logged in shs pts/0 192.168.0.6 Wed Jun 17 18:10 - 18:42 (00:32) reboot system boot 5.4.0-37-generic Wed Jun 17 17:58 still running shs pts/2 192.168.0.6 Wed Jun 17 17:22 - 17:57 (00:34) $ last nemo | head -5 nemo pts/1 192.168.0.6 Fri Jun 19 12:58 - 16:21 (03:22) nemo pts/2 192.168.0.6 Sat Jun 13 17:49 - 19:05 (01:16) nemo pts/1 192.168.0.6 Thu Jun 4 17:33 - 17:44 (00:10) nemo pts/1 192.168.0.19 Mon May 11 19:04 - 19:57 (00:52) nemo pts/1 192.168.0.19 Tue May 5 12:46 - 17:49 (05:02)
du命令
如果针对/home中的每个目录运行,du命令会报告每个用户的主目录在使用多少空间,就像这样:
$ sudo du -sk /home/* 289 /home/dorothy 116 /home/dory 88 /home/eel 28 /home/gino 28 /home/jadep 12764 /home/nemo 732 /home/shark 418046 /home/shs 108 /home/tadpole
默认情况下,报告的大小以1024字节为单位。
ps和history命令
针对当前登录的用户,您始终可以使用ps -ef | grep ^nemo之类的命令,查看用户目前在运行哪些命令和进程。想查看以前运行的命令,可以试着查看用户的历史记录文件(比如.bash_history),不过要注意,用户可以设置帐户,以便某些命令不被捕获到历史记录文件中,他们还可以编辑这些文件,如果选择这么做的话。
统计登录次数
如果您想查看自/var/log/wtmp文件上一次翻转以来每个用户登录的次数,可以使用这样的命令:
$ for USER in `ls /home` > do > cnt=`last $USER | grep ^$USER | wc -l` # count logins > echo $USER: $cnt # show login count > done
输出会像是这样:
dorothy: 0 dory: 0 eel: 8 gino: 0 jadep: 102 nemo: 39 shark: 50 shs: 105 tadpole: 0
如果您想要更多的细节,可以创建一个较复杂的脚本,以便添加另外一些信息,比如登录细节和格式。
#!/bin/bash sepline="====================" for USER in `ls /home` do len=`echo $USER | awk '{print length($0)}'` # get length of username echo $USER sep="${sepline:1:$len}" # set separator echo $sep # print separator cnt=`last $USER | grep ^$USER | wc -l` # count logins echo logins: $cnt # show login count last $USER | grep ^$USER | head -5 # show most recent logins echo done
上述脚本将显示的数据限制在最近的五次登录,但是您可以轻松改变。以下是一个用户的数据的格式会什么样:
shs === logins: 105 shs pts/0 192.168.0.6 Fri Jun 19 12:57 still logged in shs pts/0 192.168.0.6 Wed Jun 17 18:10 - 18:42 (00:32) shs pts/2 192.168.0.6 Wed Jun 17 17:22 - 17:57 (00:34) shs pts/0 192.168.0.25 Wed Jun 17 17:20 - 17:57 (00:36) shs pts/1 192.168.0.6 Wed Jun 17 15:19 - 17:57 (02:38)
检查企图使用sudo的情况
如果您想看看用户中有谁企图使用sudo、而他们本无这项权限,可以运行这样的命令:
$ grep "NOT in sudoers" /var/log/auth.log | awk '{print $6}' nemo
如果您在无权提升权限的情况下试图使用sudo,而系统发出警告信息“用户名不在sudoers文件中。将报告该事件”,您可能会知道这个日志条目是该报告的精髓。除非管理员竭力寻找sudo使用违规,否则它们不会被人注意。
To sum up, the behavioral characteristics of Linux users are very unique, and their preferred operating methods and behavioral habits are constantly evolving. Through the introduction of this article, we have learned about the behavior analysis of Linux users, mastered the methods and techniques of analyzing Linux user behavior, and can better understand and apply this excellent operating system.
The above is the detailed content of Exploring the behavior analysis of Linux users. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

For many users, hacking an Android TV box sounds daunting. However, developer Murray R. Van Luyn faced the challenge of looking for suitable alternatives to the Raspberry Pi during the Broadcom chip shortage. His collaborative efforts with the Armbia

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

How to download BitPie Bitpie Wallet App? The steps are as follows: Search for "BitPie Bitpie Wallet" in the AppStore (Apple devices) or Google Play Store (Android devices). Click the "Get" or "Install" button to download the app. For the computer version, visit the official BitPie wallet website and download the corresponding software package.

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

1. Installation environment (Hyper-V virtual machine): $hostnamectlStatichostname:localhost.localdomainIconname:computer-vmChassis:vmMachineID:renwoles1d8743989a40cb81db696400BootID:renwoles272f4aa59935dcdd0d456501Virtualization:microsoftOperatingSystem:CentOS Linux7(Core)CPEOSName:cpe:

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.
