Show IP address in history

On Linux Server, history command shows previously executed commands. If you have many people working on a server, it is better log IP address of the user who run the command along with time for security reason.

To log, IP and date, create file

In the file, add

Make it executable

Create file

Add following to the file

Logout and login to server. Now your history will also record IP address that is used to login to server. PROMPT_COMMAND environment variable allow you to execute a command every time command promt is shown. To see how PROMPT_COMMAND works, just run

Example

Every time i press enter, command specified in PROMPT_COMMAND variable get executed. Just close the current terminal to undo the change.

See history

Leave a Reply

Your email address will not be published. Required fields are marked *