{"id":348,"date":"2020-05-28T18:09:51","date_gmt":"2020-05-29T01:09:51","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=348"},"modified":"2020-05-28T18:09:51","modified_gmt":"2020-05-29T01:09:51","slug":"allow-ssh-for-specific-ip-address-and-block-all-others","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=348","title":{"rendered":"Allow SSH for specific IP Address and block all others"},"content":{"rendered":"\n<p>Allow SSH for specific IP Address and block all others<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Solution 1:<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">Using \/etc\/hosts.allow And \/etc\/hosts.deny File<\/h1>\n\n\n\n<p>SSHD will first check \/etc\/hosts.allow for entries. If there is no rule in \/etc\/hosts.allow which fits SSHD will go on checking \/etc\/hosts.deny for rules.<\/p>\n\n\n\n<p>So you need to add:<\/p>\n\n\n\n<p>vim \/etc\/hosts.deny<\/p>\n\n\n\n<p><em>sshd: ALL EXCEPT LOCAL<\/em><\/p>\n\n\n\n<p>To block every SSH connection, except localhost, which is not in \/etc\/hosts.allow.<\/p>\n\n\n\n<p>vim \/etc\/hosts.allow<\/p>\n\n\n\n<p><em>sshd: 192.168.178.10<\/em><\/p>\n\n\n\n<p><em>sshd: 192.168.178.11<\/em><\/p>\n\n\n\n<p><em>sshd: 192.168.178.10\/255.255.255.0<\/em><\/p>\n\n\n\n<p>To allow specific IPs. Last rule is an example for an IP range.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Solution 2:<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">Using iptables<\/h1>\n\n\n\n<p>However using \/etc\/hosts.allow and \/etc\/hosts.deny is not the recommended method to allow SSH only for a few IPs. You should consider using iptables for that job.<\/p>\n\n\n\n<p>You could allow SSH for a specific IP by using a rule like:<\/p>\n\n\n\n<p><em>iptables -A INPUT -m state &#8211;state NEW,ESTABLISHED,RELATED &#8211;source x.x.x.x -p tcp &#8211;dport 22 -j ACCEPT<\/em><\/p>\n\n\n\n<p><em>iptables -A INPUT -m state &#8211;state NEW,ESTABLISHED,RELATED -p tcp &#8211;dport 22 -j DROP<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Allow SSH for specific IP Address and block all others Solution 1: Using \/etc\/hosts.allow And \/etc\/hosts.deny File SSHD will first check \/etc\/hosts.allow for entries. If there is no rule in \/etc\/hosts.allow which fits SSHD will go on checking \/etc\/hosts.deny for rules. So you need to add: vim \/etc\/hosts.deny sshd: ALL EXCEPT LOCAL To block every <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=348\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-348","post","type-post","status-publish","format-standard","hentry","category-linux"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Allow SSH for specific IP Address and block all others Solution 1: Using \/etc\/hosts.allow And \/etc\/hosts.deny File SSHD will first check \/etc\/hosts.allow for entries. If there is no rule in \/etc\/hosts.allow which fits SSHD will go on checking \/etc\/hosts.deny for rules. So you need to add: vim \/etc\/hosts.deny sshd: ALL EXCEPT LOCAL To block every\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Summa Lai\"\/>\n\t<meta name=\"keywords\" content=\"linux family\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/SUMMALAI.COM\/?p=348\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#article\",\"name\":\"Allow SSH for specific IP Address and block all others | Summa Lai\",\"headline\":\"Allow SSH for specific IP Address and block all others\",\"author\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?author=2#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#articleImage\",\"url\":\"https:\\\/\\\/SUMMALAI.COM\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/Summa_Logo-150x150.png\",\"width\":96,\"height\":96,\"caption\":\"Summa Lai\"},\"datePublished\":\"2020-05-28T18:09:51-07:00\",\"dateModified\":\"2020-05-28T18:09:51-07:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#webpage\"},\"articleSection\":\"Linux Family\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/SUMMALAI.COM\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?cat=5#listItem\",\"name\":\"Linux Family\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?cat=5#listItem\",\"position\":2,\"name\":\"Linux Family\",\"item\":\"https:\\\/\\\/SUMMALAI.COM\\\/?cat=5\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#listItem\",\"name\":\"Allow SSH for specific IP Address and block all others\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#listItem\",\"position\":3,\"name\":\"Allow SSH for specific IP Address and block all others\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?cat=5#listItem\",\"name\":\"Linux Family\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/#person\",\"name\":\"sladmin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#personImage\",\"url\":\"https:\\\/\\\/SUMMALAI.COM\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/Summa_Logo-150x150.png\",\"width\":96,\"height\":96,\"caption\":\"sladmin\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?author=2#author\",\"url\":\"https:\\\/\\\/SUMMALAI.COM\\\/?author=2\",\"name\":\"Summa Lai\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#authorImage\",\"url\":\"https:\\\/\\\/SUMMALAI.COM\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/Summa_Logo-150x150.png\",\"width\":96,\"height\":96,\"caption\":\"Summa Lai\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#webpage\",\"url\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348\",\"name\":\"Allow SSH for specific IP Address and block all others | Summa Lai\",\"description\":\"Allow SSH for specific IP Address and block all others Solution 1: Using \\\/etc\\\/hosts.allow And \\\/etc\\\/hosts.deny File SSHD will first check \\\/etc\\\/hosts.allow for entries. If there is no rule in \\\/etc\\\/hosts.allow which fits SSHD will go on checking \\\/etc\\\/hosts.deny for rules. So you need to add: vim \\\/etc\\\/hosts.deny sshd: ALL EXCEPT LOCAL To block every\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?p=348#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?author=2#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/?author=2#author\"},\"datePublished\":\"2020-05-28T18:09:51-07:00\",\"dateModified\":\"2020-05-28T18:09:51-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/#website\",\"url\":\"https:\\\/\\\/SUMMALAI.COM\\\/\",\"name\":\"Summa Lai\",\"description\":\"Never Stop Learning, Building a Little Wiki...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/SUMMALAI.COM\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Allow SSH for specific IP Address and block all others | Summa Lai","description":"Allow SSH for specific IP Address and block all others Solution 1: Using \/etc\/hosts.allow And \/etc\/hosts.deny File SSHD will first check \/etc\/hosts.allow for entries. If there is no rule in \/etc\/hosts.allow which fits SSHD will go on checking \/etc\/hosts.deny for rules. So you need to add: vim \/etc\/hosts.deny sshd: ALL EXCEPT LOCAL To block every","canonical_url":"https:\/\/SUMMALAI.COM\/?p=348","robots":"max-image-preview:large","keywords":"linux family","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/SUMMALAI.COM\/?p=348#article","name":"Allow SSH for specific IP Address and block all others | Summa Lai","headline":"Allow SSH for specific IP Address and block all others","author":{"@id":"https:\/\/SUMMALAI.COM\/?author=2#author"},"publisher":{"@id":"https:\/\/SUMMALAI.COM\/#person"},"image":{"@type":"ImageObject","@id":"https:\/\/SUMMALAI.COM\/?p=348#articleImage","url":"https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2020\/05\/Summa_Logo-150x150.png","width":96,"height":96,"caption":"Summa Lai"},"datePublished":"2020-05-28T18:09:51-07:00","dateModified":"2020-05-28T18:09:51-07:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/SUMMALAI.COM\/?p=348#webpage"},"isPartOf":{"@id":"https:\/\/SUMMALAI.COM\/?p=348#webpage"},"articleSection":"Linux Family"},{"@type":"BreadcrumbList","@id":"https:\/\/SUMMALAI.COM\/?p=348#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/SUMMALAI.COM#listItem","position":1,"name":"Home","item":"https:\/\/SUMMALAI.COM","nextItem":{"@type":"ListItem","@id":"https:\/\/SUMMALAI.COM\/?cat=5#listItem","name":"Linux Family"}},{"@type":"ListItem","@id":"https:\/\/SUMMALAI.COM\/?cat=5#listItem","position":2,"name":"Linux Family","item":"https:\/\/SUMMALAI.COM\/?cat=5","nextItem":{"@type":"ListItem","@id":"https:\/\/SUMMALAI.COM\/?p=348#listItem","name":"Allow SSH for specific IP Address and block all others"},"previousItem":{"@type":"ListItem","@id":"https:\/\/SUMMALAI.COM#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/SUMMALAI.COM\/?p=348#listItem","position":3,"name":"Allow SSH for specific IP Address and block all others","previousItem":{"@type":"ListItem","@id":"https:\/\/SUMMALAI.COM\/?cat=5#listItem","name":"Linux Family"}}]},{"@type":"Person","@id":"https:\/\/SUMMALAI.COM\/#person","name":"sladmin","image":{"@type":"ImageObject","@id":"https:\/\/SUMMALAI.COM\/?p=348#personImage","url":"https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2020\/05\/Summa_Logo-150x150.png","width":96,"height":96,"caption":"sladmin"}},{"@type":"Person","@id":"https:\/\/SUMMALAI.COM\/?author=2#author","url":"https:\/\/SUMMALAI.COM\/?author=2","name":"Summa Lai","image":{"@type":"ImageObject","@id":"https:\/\/SUMMALAI.COM\/?p=348#authorImage","url":"https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2020\/05\/Summa_Logo-150x150.png","width":96,"height":96,"caption":"Summa Lai"}},{"@type":"WebPage","@id":"https:\/\/SUMMALAI.COM\/?p=348#webpage","url":"https:\/\/SUMMALAI.COM\/?p=348","name":"Allow SSH for specific IP Address and block all others | Summa Lai","description":"Allow SSH for specific IP Address and block all others Solution 1: Using \/etc\/hosts.allow And \/etc\/hosts.deny File SSHD will first check \/etc\/hosts.allow for entries. If there is no rule in \/etc\/hosts.allow which fits SSHD will go on checking \/etc\/hosts.deny for rules. So you need to add: vim \/etc\/hosts.deny sshd: ALL EXCEPT LOCAL To block every","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/SUMMALAI.COM\/#website"},"breadcrumb":{"@id":"https:\/\/SUMMALAI.COM\/?p=348#breadcrumblist"},"author":{"@id":"https:\/\/SUMMALAI.COM\/?author=2#author"},"creator":{"@id":"https:\/\/SUMMALAI.COM\/?author=2#author"},"datePublished":"2020-05-28T18:09:51-07:00","dateModified":"2020-05-28T18:09:51-07:00"},{"@type":"WebSite","@id":"https:\/\/SUMMALAI.COM\/#website","url":"https:\/\/SUMMALAI.COM\/","name":"Summa Lai","description":"Never Stop Learning, Building a Little Wiki...","inLanguage":"en-US","publisher":{"@id":"https:\/\/SUMMALAI.COM\/#person"}}]}},"aioseo_meta_data":{"post_id":"348","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-20 22:04:38","updated":"2024-01-12 04:29:00","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/SUMMALAI.COM\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/SUMMALAI.COM\/?cat=5\" title=\"Linux Family\">Linux Family<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tAllow SSH for specific IP Address and block all others\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/SUMMALAI.COM"},{"label":"Linux Family","link":"https:\/\/SUMMALAI.COM\/?cat=5"},{"label":"Allow SSH for specific IP Address and block all others","link":"https:\/\/SUMMALAI.COM\/?p=348"}],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=348"}],"version-history":[{"count":0,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}