{"id":33,"date":"2013-11-25T22:45:46","date_gmt":"2013-11-25T22:45:46","guid":{"rendered":"http:\/\/etapien.com\/guides\/?p=33"},"modified":"2020-08-24T14:22:37","modified_gmt":"2020-08-24T19:22:37","slug":"how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh","status":"publish","type":"post","link":"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/","title":{"rendered":"How to get email alerts when someone logs in as root via SSH"},"content":{"rendered":"<p>This is a very useful script that will alert you whenever someone logs into your server via ssh, it you ever get this and it&#8217;s not you, then it may be too late but who knows, there may be a way to do something about it before it gets worse.<\/p>\n<p>To setup email notification, login to your server as root.<br \/>\nEdit .bashrc<\/p>\n<pre><code>\r\nnano .bashrc\r\n<\/code><\/pre>\n<p>add the following line at the end, changing \u201cServerName\u201d to the hostname of your server and \u201cemail@thisaddress.com\u201d to your own email address.<\/p>\n<pre><code>echo 'ALERT - Root Shell Access (ServerName) on:' `date` `who` | mail -s \"Alert on ServerName: Root Access from `who | cut -d\"(\" -f2 | cut -d\")\" -f1`\" youremail@address.com\r\n<\/code><\/pre>\n<p>Make sure to change ServerName for the real server name and the email address it will be sent to, save and exit.<\/p>\n<p>If you&#8217;re on CenOS you can add:<\/p>\n<p>-r &#8220;ServerName Root Login Alert &lt;noreply@servername.domain.com&gt;&#8221;<\/p>\n<p>right before your email address and it will set a from name and email,<\/p>\n<p>for Debian that would be:<\/p>\n<p>-a &#8220;From: ServerName Root Login Alert &lt;noreply@servername.domain.com&gt;&#8221;<\/p>\n<p>Next time someone logs on as root, you will get an email about this and this can be done for any user, you only have to make sure that the user can email out from your server.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.debian-tutorials.com\/set-e-mail-alert-on-root-ssh-login\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a very useful script that will alert you whenever someone logs into your server via ssh, it you ever get this and it&#8217;s not you, then it may be too late but who knows, there may be a way to do something about it before it gets worse.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get email alerts when someone logs in as root via SSH - Tech Howtos<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get email alerts when someone logs in as root via SSH - Tech Howtos\" \/>\n<meta property=\"og:description\" content=\"This is a very useful script that will alert you whenever someone logs into your server via ssh, it you ever get this and it&#039;s not you, then it may be too late but who knows, there may be a way to do something about it before it gets worse.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech Howtos\" \/>\n<meta property=\"article:published_time\" content=\"2013-11-25T22:45:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-24T19:22:37+00:00\" \/>\n<meta name=\"author\" content=\"Etapien\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Etapien\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/\",\"url\":\"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/\",\"name\":\"How to get email alerts when someone logs in as root via SSH - Tech Howtos\",\"isPartOf\":{\"@id\":\"https:\/\/etapien.com\/guides\/#website\"},\"datePublished\":\"2013-11-25T22:45:46+00:00\",\"dateModified\":\"2020-08-24T19:22:37+00:00\",\"author\":{\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\"},\"breadcrumb\":{\"@id\":\"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/etapien.com\/guides\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get email alerts when someone logs in as root via SSH\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/etapien.com\/guides\/#website\",\"url\":\"https:\/\/etapien.com\/guides\/\",\"name\":\"Tech Howtos\",\"description\":\"Tech related useful howtos\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/etapien.com\/guides\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\",\"name\":\"Etapien\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"caption\":\"Etapien\"},\"url\":\"https:\/\/etapien.com\/guides\/author\/Etapien\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get email alerts when someone logs in as root via SSH - Tech Howtos","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/","og_locale":"en_US","og_type":"article","og_title":"How to get email alerts when someone logs in as root via SSH - Tech Howtos","og_description":"This is a very useful script that will alert you whenever someone logs into your server via ssh, it you ever get this and it's not you, then it may be too late but who knows, there may be a way to do something about it before it gets worse.","og_url":"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/","og_site_name":"Tech Howtos","article_published_time":"2013-11-25T22:45:46+00:00","article_modified_time":"2020-08-24T19:22:37+00:00","author":"Etapien","twitter_misc":{"Written by":"Etapien","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/","url":"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/","name":"How to get email alerts when someone logs in as root via SSH - Tech Howtos","isPartOf":{"@id":"https:\/\/etapien.com\/guides\/#website"},"datePublished":"2013-11-25T22:45:46+00:00","dateModified":"2020-08-24T19:22:37+00:00","author":{"@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424"},"breadcrumb":{"@id":"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/etapien.com\/guides\/how-to-get-email-alets-when-someone-logs-in-as-root-via-ssh\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/etapien.com\/guides\/"},{"@type":"ListItem","position":2,"name":"How to get email alerts when someone logs in as root via SSH"}]},{"@type":"WebSite","@id":"https:\/\/etapien.com\/guides\/#website","url":"https:\/\/etapien.com\/guides\/","name":"Tech Howtos","description":"Tech related useful howtos","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/etapien.com\/guides\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424","name":"Etapien","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","caption":"Etapien"},"url":"https:\/\/etapien.com\/guides\/author\/Etapien\/"}]}},"_links":{"self":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":5,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/33\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}