In Linux, view User Login Operation Records

Source: Internet
Author: User
Article Title: in Linux, view User Logon Operation Records. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In a linux system, whether the root user or other users log on to the system and use the command history to view the historical records. However, if multiple users log on to a server, one day, someone accidentally deleted important data.

At this time, it makes no sense to view the history (command: history. Is there any way to record the IP address after login and the history of operations performed by a user name? Answer: Yes.

You can add the following code to/etc/profile:

PS1 = "'whoam' @ 'hostname':" '[$ PWD]'

History

USER_IP = 'Who-u am I 2>/dev/null | awk '{print $ NF}' | sed-e's/[()] // g''

If ["$ USER_IP" = ""]

Then

USER_IP = 'hostname'

Fi

If [! -D/tmp/dbasky]

Then

Mkdir/tmp/dbasky

Chmod 777/tmp/dbasky

Fi

If [! -D/tmp/dbasky/$ {LOGNAME}]

Then

Mkdir/tmp/dbasky/$ {LOGNAME}

Chmod 300/tmp/dbasky/$ {LOGNAME}

Fi

Export HISTSIZE = 4096

DT = 'date "% Y % m % d _ % H % M % S "'

Export HISTFILE = "/tmp/dbasky/$ {LOGNAME}/$ {USER_IP} dbasky. $ DT"

Chmod 600/tmp/dbasky/$ {LOGNAME}/* dbasky * 2>/dev/null

In fact, the above Code cannot tell you that it is very convenient to create a dbasky directory in/tmp of the system and record all users and IP addresses that have logged on to the system in the directory? We can also use this method to monitor system security.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.