{"id":11497,"date":"2019-03-14T09:30:04","date_gmt":"2019-03-14T09:30:04","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11497"},"modified":"2019-03-14T09:30:04","modified_gmt":"2019-03-14T09:30:04","slug":"how-to-monitor-linux-commands-executed-by-system-users-in-real-time","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/how-to-monitor-linux-commands-executed-by-system-users-in-real-time\/","title":{"rendered":"How to Monitor Linux Commands Executed by System Users in Real-time"},"content":{"rendered":"<p>Are you a Linux system administrator and want to monitor interactive activity of all system users (Linux commands they executes) in real-time. In this brief Linux system security guide, we will explain how to view all Linux shell commands executed by system users in real-time.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-monitor-user-activity-with-psacct-or-acct-tools\/\" target=\"_blank\" rel=\"noopener\">How to Monitor User Activity with psacct or acct Tools<\/a><\/p>\n<p>If your system has\u00a0<strong>bash<\/strong>, the most commonly used shell out there then all commands executed by normal system users will be stored in the\u00a0<code>.bash_history<\/code>\u00a0hidden file which is kept in each user\u2019s home directory. The content of this file can be viewed by users, using the\u00a0<a href=\"https:\/\/www.tecmint.com\/history-command-examples\/\" target=\"_blank\" rel=\"noopener\">history command<\/a>.<\/p>\n<p>To view a user\u00a0<strong>aaronkilik\u2019s<\/strong>\u00a0<code>.bash_history<\/code>\u00a0file, type:<\/p>\n<pre># cat \/home\/aaronkilik\/.bash_history\r\n<\/pre>\n<div id=\"attachment_27149\" class=\"wp-caption aligncenter\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27149\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/User-bash-history-file.png\" alt=\"User bash-history file\" width=\"562\" height=\"97\" data-lazy-loaded=\"true\" \/><\/p>\n<p class=\"wp-caption-text\">User bash-history file<\/p>\n<p>From the screen shot above, the\u00a0<strong>date<\/strong>\u00a0and\u00a0<strong>time<\/strong>\u00a0when a command was executed is not shown. This is the default setting on most if not all Linux distributions.<\/p>\n<p>You can follow this guide to\u00a0<a href=\"https:\/\/www.tecmint.com\/display-linux-command-history-with-date-and-time\/\" target=\"_blank\" rel=\"noopener\">set date and time for each command in bash_history file<\/a>.<\/p>\n<h3>Monitor User Activity in Real-time Using Sysdig in Linux<\/h3>\n<p>To get a glimpse of what users are doing on the system, you can use the\u00a0<code>w<\/code>\u00a0command as follows.<\/p>\n<pre># w\r\n<\/pre>\n<div id=\"attachment_27150\" class=\"wp-caption aligncenter\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27150\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Monitor-Logged-in-Users.png\" alt=\"Monitor Logged in Users\" width=\"712\" height=\"135\" data-lazy-loaded=\"true\" \/><\/p>\n<p class=\"wp-caption-text\">Monitor Logged in Users<\/p>\n<\/div>\n<p>But to have a real-time view of the shell commands being run by another user logged in via a terminal or SSH, you can use the\u00a0<a href=\"https:\/\/www.tecmint.com\/sysdig-system-monitoring-and-troubleshooting-tool-for-linux\/\" target=\"_blank\" rel=\"noopener\">Sysdig tool in Linux<\/a>.<\/p>\n<p><strong>Sydig<\/strong>\u00a0is an open-source, cross-platform, powerful and flexible system monitoring, analysis and troubleshooting tool for Linux. It can be used for system exploration and debugging.<\/p>\n<p>Once you have installed\u00a0<strong>sysdig<\/strong>, use the\u00a0<code>spy_users<\/code>\u00a0chisel to spy on users by running the command below.<\/p>\n<pre># sysdig -c spy_users\r\n<\/pre>\n<p>The above command displays every command that users launch interactively as well as every directory users visit.<\/p>\n<div id=\"attachment_27151\" class=\"wp-caption aligncenter\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27151\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Monitor-User-Activity-in-Real-Time.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Monitor-User-Activity-in-Real-Time.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/09\/Monitor-User-Activity-in-Real-Time-768x384.png 768w\" alt=\"Monitor User Activity in Real-Time\" width=\"802\" height=\"401\" data-lazy-loaded=\"true\" \/><\/p>\n<p class=\"wp-caption-text\">Monitor User Activity in Real-Time<\/p>\n<\/div>\n<p>That\u2019s all, you can also check out these following related articles:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/linux-server-hardening-security-tips\/\" target=\"_blank\" rel=\"noopener\">25 Hardening Security Tips for Linux Servers<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/linux-security-auditing-and-scanning-with-lynis-tool\/\" target=\"_blank\" rel=\"noopener\">Lynis \u2013 Security Auditing and Scanning Tool for Linux Systems<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/open-source-security-firewalls-for-linux-systems\/\" target=\"_blank\" rel=\"noopener\">10 Useful Open Source Security Firewalls for Linux Systems<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/nmap-network-security-scanner-in-kali-linux\/\" target=\"_blank\" rel=\"noopener\">A Practical Guide to Nmap (Network Security Scanner) in Linux<\/a><\/li>\n<\/ol>\n<p>In this system security guide, we described how to view users bash history file, show logged on users and what they are doing, and we also explained how to view or monitor all commands executed by system users in real-time.<\/p>\n<p>If you want to share any other methods or ask questions, please do so via the comment section below.<\/p>\n<p><a style=\"font-size: 1rem;\" href=\"https:\/\/www.tecmint.com\/monitor-linux-commands-executed-by-system-users-in-real-time\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Are you a Linux system administrator and want to monitor interactive activity of all system users (Linux commands they executes) in real-time. In this brief Linux system security guide, we will explain how to view all Linux shell commands executed by system users in real-time. Read Also:\u00a0How to Monitor User Activity with psacct or acct &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/how-to-monitor-linux-commands-executed-by-system-users-in-real-time\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Monitor Linux Commands Executed by System Users in Real-time&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11497","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11497"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11497\/revisions"}],"predecessor-version":[{"id":11498,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11497\/revisions\/11498"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}