{"id":298,"date":"2021-03-26T15:16:12","date_gmt":"2021-03-26T15:16:12","guid":{"rendered":"https:\/\/andrejacobs.org\/?p=298"},"modified":"2022-04-11T20:24:23","modified_gmt":"2022-04-11T20:24:23","slug":"home-automation-enable-ssh-on-home-assistant","status":"publish","type":"post","link":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/","title":{"rendered":"Home Automation – Enable SSH on Home Assistant"},"content":{"rendered":"\n

As part of Day 18<\/a> of my 100 Days of Learning<\/a> I wanted to upgrade my Home Assistant<\/a> setup to run from an external SSD. There is a well known issue that SD cards on Raspberry Pis corrupt after a while and also I didn’t want Home Assistant to fill up the SD card too quickly.<\/p>\n

I am running Home Assistant on a Raspberry Pi 3B and I would like to be able to SSH into it. By default the Home Assistant OS does not have SSH enabled and you need to install an add-on to be able to do this.<\/p>\n

SSH into the Raspberry Pi 3B<\/h3>\n
$ ssh homeassistant.local\nssh: connect to host homeassistant.local port 22: Connection refused\n<\/code><\/pre>\n

You need to install an add-on to get SSH working. But first you need to enable Advanced mode<\/a> so that extra add-ons can be searched for on the dashboard.<\/p>\n

To install the add-on go to the Supervisor Add-on Store<\/a> and search for ssh.<\/p>\n

\"\"<\/p>\n

I am installing the Official "Terminal & SSH" add-on because the community one’s security rating is pretty low.<\/p>\n

Enabled the Watchdog and Show in sidebar.<\/p>\n

\"\"<\/p>\n

Interestingly this comes with a web terminal.<\/p>\n

\"\"<\/p>\n

Remote SSH access from the network is disabled by default.<\/strong> +10 in my book.<\/p>\n

I will generate a new SSH key pair to be used only with Home Assistant and this Raspberry Pi.<\/p>\n

$ ssh-keygen -t rsa -b 4096 -f ~\/.ssh\/id_rsa_homeassistant -C "Home Assistant RPi"\n\nGenerating public\/private rsa key pair.\nEnter passphrase (empty for no passphrase):\nEnter same passphrase again:\nYour identification has been saved in .ssh\/id_rsa_homeassistant.\nYour public key has been saved in .ssh\/id_rsa_homeassistant.pub.\nThe key fingerprint is:\nSHA256:i0MllcT0ioS\/6ab9vD\/gsVNOmnMBCYrP17w4gBS4QuY Home Assistant RPi\nThe key's randomart image is:\n+---[RSA 4096]----+\n| .     ++.       |\n|.o.  ...o.       |\n|+. o..o....      |\n|oEo .o +o.       |\n|.. +  +oS.       |\n|  . +..+=.+      |\n|     o=o.@ .     |\n|     o+oO +      |\n|    .ooo+*..     |\n+----[SHA256]-----+\n\n# Added this to my Mac's keychain\n$ ssh-add -K ~\/.ssh\/id_rsa_homeassistant\n<\/code><\/pre>\n

Added the newly created id_rsa_homeassistant and .pub file to my password manager.<\/p>\n

Interestingly enough I have always wondered about what this randomart is about and it turns out<\/a> that it is supposed to be a visual way for humans to identify if the server you are connecting to is what you would expect. However I have never seen this other than during the key generation phase.<\/p>\n

Configure the SSH server. Go to the Configuration tab for the add-on.<\/p>\n

# First you will need to copy the PUBLIC key\n$ cat ~\/.ssh\/id_rsa_homeassistant.pub | pbcopy\n<\/code><\/pre>\n

Add the public key to the authorized_keys section and save. To expose the port from the docker container to the host OS enter a port number in the Network section and save.<\/p>\n

\"\"<\/p>\n

Check the log tab to confirm it is working on Home Assistant.<\/p>\n

[10:37:38] INFO: Starting the SSH daemon...\nServer listening on 0.0.0.0 port 22.\nServer listening on :: port 22.\n<\/code><\/pre>\n

Connect using SSH. I like to have a SSH key pair per host I connect to and thus for the initial test connection I specify the key to use (option -i<\/code>) before I add this to my ~\/.ssh\/config<\/code> file. Because of my config I need to also tell ssh to use the publickey or the connections will be denied. As a bonus I figured I would give this visual randomart thing a try as well (-o VisualHostKey=yes<\/code>).<\/p>\n

$ ssh -i ~\/.ssh\/id_rsa_homeassistant -o PreferredAuthentications=publickey -o VisualHostKey=yes root@homeassistant.local\nHost key fingerprint is SHA256:A98IsXgCboFFWUTG64OclRgiH0uMsSaUCpIaV5NJ9Ds\n+---[ECDSA 256]---+\n|.X*XXo.          |\n|@+B+++ o         |\n|OBo=oo*          |\n|=.+ +o = o       |\n| . =  E S .      |\n|  + o  . .       |\n|     .           |\n|                 |\n|                 |\n+----[SHA256]-----+\n\n| |  | |                          \/\\           (_)   | |            | |\n| |__| | ___  _ __ ___   ___     \/  \\   ___ ___ _ ___| |_ __ _ _ __ | |_\n|  __  |\/ _ \\| '_ \\ _ \\ \/ _ \\   \/ \/\\ \\ \/ __\/ __| \/ __| __\/ _\\ | '_ \\| __|\n| |  | | (_) | | | | | |  __\/  \/ ____ \\\\__ \\__ \\ \\__ \\ || (_| | | | | |_\n|_|  |_|\\___\/|_| |_| |_|\\___| \/_\/    \\_\\___\/___\/_|___\/\\__\\__,_|_| |_|\\__|\n\nWelcome to the Home Assistant command line.\n\nSystem information\n  IPv4 addresses for eth0:  192.168.1.69\/24\n  IPv6 addresses for eth0:  fe80::4dbc:b38d:4441:bf58\/64\n  IPv4 addresses for wlan0:\n\n  OS Version:               Home Assistant OS 5.12\n  Home Assistant Core:      2021.3.4\n\n  Home Assistant URL:       http:\/\/homeassistant.local:8123\n  Observer URL:             http:\/\/homeassistant.local:4357\n~ $\n<\/code><\/pre>\n

Ok that worked so I can now add it to my ~\/.ssh\/config<\/code> so that the command just becomes ssh root@homeassistant.local<\/code> from now on.<\/p>\n

# ~\/.ssh\/config\n\n# Home Assistant running on Rasperry Pi\nHost homeassistant.local\n\tHostName homeassistant.local\n\tPreferredAuthentications publickey\n\tIdentityFile ~\/.ssh\/id_rsa_homeassistant\n\tIdentitiesOnly yes\n  VisualHostKey=yes\n\tPort 22\n<\/code><\/pre>\n

After that worked I changed the port number in the Configuration tab as well as my ~\/.ssh\/config<\/code> file. I rarely use default ports.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

[…]<\/p>\n

Read more →<\/a><\/p>\n","protected":false},"author":2,"featured_media":305,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[37,29],"tags":[30,31],"yoast_head":"\nHome Automation - Enable SSH on Home Assistant - Andr\u00e9 Jacobs<\/title>\n<meta name=\"description\" content=\"In this post I will show you how I have enabled SSH in Home Assistant OS running on a Raspberry Pi 3B. Part of my Home Automation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Home Automation - Enable SSH on Home Assistant - Andr\u00e9 Jacobs\" \/>\n<meta property=\"og:description\" content=\"In this post I will show you how I have enabled SSH in Home Assistant OS running on a Raspberry Pi 3B. Part of my Home Automation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/\" \/>\n<meta property=\"og:site_name\" content=\"Andr\u00e9 Jacobs\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-26T15:16:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-11T20:24:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/andrejacobs.org\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-26-at-15.11.56.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1620\" \/>\n\t<meta property=\"og:image:height\" content=\"1086\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Andr\u00e9 Jacobs\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@andrejacobs81\" \/>\n<meta name=\"twitter:site\" content=\"@andrejacobs81\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andr\u00e9 Jacobs\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/\"},\"author\":{\"name\":\"Andr\u00e9 Jacobs\",\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\"},\"headline\":\"Home Automation – Enable SSH on Home Assistant\",\"datePublished\":\"2021-03-26T15:16:12+00:00\",\"dateModified\":\"2022-04-11T20:24:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/\"},\"wordCount\":464,\"publisher\":{\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\"},\"keywords\":[\"home assistant\",\"raspberry pi\"],\"articleSection\":[\"100 Days Challenge\",\"Home Automation\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/\",\"url\":\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/\",\"name\":\"Home Automation - Enable SSH on Home Assistant - Andr\u00e9 Jacobs\",\"isPartOf\":{\"@id\":\"https:\/\/andrejacobs.org\/#website\"},\"datePublished\":\"2021-03-26T15:16:12+00:00\",\"dateModified\":\"2022-04-11T20:24:23+00:00\",\"description\":\"In this post I will show you how I have enabled SSH in Home Assistant OS running on a Raspberry Pi 3B. Part of my Home Automation.\",\"breadcrumb\":{\"@id\":\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/andrejacobs.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Home Automation – Enable SSH on Home Assistant\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/andrejacobs.org\/#website\",\"url\":\"https:\/\/andrejacobs.org\/\",\"name\":\"Andr\u00e9 Jacobs\",\"description\":\"iOS Development, Electronics, Robotics, Artificial Intelligence, Business and Health\",\"publisher\":{\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/andrejacobs.org\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\",\"name\":\"Andr\u00e9 Jacobs\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg\",\"contentUrl\":\"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg\",\"width\":450,\"height\":450,\"caption\":\"Andr\u00e9 Jacobs\"},\"logo\":{\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/andrejacobs.org\",\"https:\/\/www.youtube.com\/channel\/UCzqXvnd_UJ3sAzQkQBD-IVw\"],\"url\":\"https:\/\/andrejacobs.org\/author\/andre\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Home Automation - Enable SSH on Home Assistant - Andr\u00e9 Jacobs","description":"In this post I will show you how I have enabled SSH in Home Assistant OS running on a Raspberry Pi 3B. Part of my Home Automation.","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:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/","og_locale":"en_GB","og_type":"article","og_title":"Home Automation - Enable SSH on Home Assistant - Andr\u00e9 Jacobs","og_description":"In this post I will show you how I have enabled SSH in Home Assistant OS running on a Raspberry Pi 3B. Part of my Home Automation.","og_url":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/","og_site_name":"Andr\u00e9 Jacobs","article_published_time":"2021-03-26T15:16:12+00:00","article_modified_time":"2022-04-11T20:24:23+00:00","og_image":[{"width":1620,"height":1086,"url":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-26-at-15.11.56.png","type":"image\/png"}],"author":"Andr\u00e9 Jacobs","twitter_card":"summary_large_image","twitter_creator":"@andrejacobs81","twitter_site":"@andrejacobs81","twitter_misc":{"Written by":"Andr\u00e9 Jacobs","Estimated reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/#article","isPartOf":{"@id":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/"},"author":{"name":"Andr\u00e9 Jacobs","@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68"},"headline":"Home Automation – Enable SSH on Home Assistant","datePublished":"2021-03-26T15:16:12+00:00","dateModified":"2022-04-11T20:24:23+00:00","mainEntityOfPage":{"@id":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/"},"wordCount":464,"publisher":{"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68"},"keywords":["home assistant","raspberry pi"],"articleSection":["100 Days Challenge","Home Automation"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/","url":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/","name":"Home Automation - Enable SSH on Home Assistant - Andr\u00e9 Jacobs","isPartOf":{"@id":"https:\/\/andrejacobs.org\/#website"},"datePublished":"2021-03-26T15:16:12+00:00","dateModified":"2022-04-11T20:24:23+00:00","description":"In this post I will show you how I have enabled SSH in Home Assistant OS running on a Raspberry Pi 3B. Part of my Home Automation.","breadcrumb":{"@id":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/andrejacobs.org\/home-automation\/home-automation-enable-ssh-on-home-assistant\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/andrejacobs.org\/"},{"@type":"ListItem","position":2,"name":"Home Automation – Enable SSH on Home Assistant"}]},{"@type":"WebSite","@id":"https:\/\/andrejacobs.org\/#website","url":"https:\/\/andrejacobs.org\/","name":"Andr\u00e9 Jacobs","description":"iOS Development, Electronics, Robotics, Artificial Intelligence, Business and Health","publisher":{"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/andrejacobs.org\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68","name":"Andr\u00e9 Jacobs","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/","url":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg","contentUrl":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg","width":450,"height":450,"caption":"Andr\u00e9 Jacobs"},"logo":{"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/andrejacobs.org","https:\/\/www.youtube.com\/channel\/UCzqXvnd_UJ3sAzQkQBD-IVw"],"url":"https:\/\/andrejacobs.org\/author\/andre\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-26-at-15.11.56.png","_links":{"self":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts\/298"}],"collection":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/comments?post=298"}],"version-history":[{"count":4,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts\/298\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts\/298\/revisions\/320"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/media\/305"}],"wp:attachment":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/media?parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/categories?post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/tags?post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}