Home Assistant is a powerful open-source home automation platform. It allows you to control and monitor your smart home devices locally, ensuring privacy and reliability. One of the most useful features is the ability to remotely access your Home Assistant instance using SSH, or Secure Shell.
This is especially handy for troubleshooting, making advanced configurations, or simply managing your smart home from anywhere. This guide will walk you through how to configure Home Assistant SSH access safely and efficiently.
We’ll cover everything from installing the necessary add-on to generating SSH keys and troubleshooting common connection issues. By the end, you’ll know how to configure Home Assistant SSH and have a secure, remote connection to your smart home.
Installing the SSH Add-on
The first step to enabling SSH access is installing the official “SSH & Web Terminal” add-on. This add-on provides a secure SSH server directly within your Home Assistant environment. To begin, navigate to your Home Assistant dashboard.
Click on “Supervisor” in the sidebar, then select the “Add-on Store” tab. Here, you’ll find a list of available add-ons; use the search bar to find “SSH & Web Terminal.”
Click on the “SSH & Web Terminal” add-on, and then click the “Install” button. The installation process may take a few minutes, so be patient while Home Assistant downloads and sets up the add-on.
Once the installation is complete, you’ll see a new page with the add-on details. Do not start the add-on yet; we need to configure it first for security.
The “SSH & Web Terminal” add-on is crucial for establishing a secure connection. It essentially acts as a bridge, allowing you to interact with your Home Assistant system through a command-line interface. This is especially useful when you need to perform tasks that aren’t easily accessible through the standard web interface.

Think of it as opening a direct line of communication to the heart of your smart home. You can directly manipulate files, execute commands, and monitor system processes, all from the comfort of your remote location. This level of access is invaluable for both advanced users and those who simply want more control over their smart home setup.
Before proceeding with the installation, ensure that your Home Assistant instance is up-to-date. Outdated software can have security vulnerabilities that could be exploited through the SSH connection. Keeping your system updated is a fundamental security practice.
Also, make sure you have a stable internet connection throughout the installation process. A dropped connection could interrupt the installation and potentially cause issues with the add-on. A reliable connection is key for a smooth setup.
Configuring the SSH Add-on
Proper configuration is essential to secure your Home Assistant SSH access. After installing the add-on, navigate to the “Configuration” tab within the “SSH & Web Terminal” add-on page.
Here, you’ll find several settings that need adjustment. First, change the default password; the default password is a major security risk, so pick a strong, unique password.
Next, consider disabling password authentication altogether and using SSH keys instead, which are more secure. You can also configure other options such as the SSH port (the default is 22, but changing it adds another layer of security) and authorized keys for key-based authentication.
After making these changes, click “Save” to apply the new configuration. It’s a good idea to restart the add-on after saving the configuration to ensure all settings are properly applied.
Choosing a strong password is more than just picking something you can remember. It involves a combination of uppercase and lowercase letters, numbers, and symbols. The longer the password, the more difficult it is to crack.
A password manager can be a great help in generating and storing complex passwords. These tools not only create strong passwords but also securely store them, so you don’t have to remember them all. This is especially useful if you have multiple accounts and services that require strong, unique passwords.
Changing the default SSH port from 22 to something else can significantly reduce the risk of automated attacks. Many malicious actors scan for open SSH ports on the default port, so changing it makes your system less visible. Choose a port number above 1024 to avoid conflicts with well-known ports.
Disabling password authentication and relying solely on SSH keys is a critical security measure. SSH keys are much harder to compromise than passwords. They rely on cryptographic principles that make them extremely resistant to brute-force attacks.
Generating SSH Keys (Optional)
For enhanced security, generating SSH keys is highly recommended. SSH keys use public-key cryptography to authenticate your connection, eliminating the need to transmit a password over the network.
This method is significantly more secure than password authentication. To generate SSH keys, you’ll need a terminal on your local computer; on Windows, you can use PuTTYgen or the built-in SSH client in recent versions of Windows 10 and 11.
| Operating System | Command | Notes |
|---|---|---|
| Linux/macOS | ssh-keygen -t rsa -b 4096 | Generates a 4096-bit RSA key pair |
| Windows (PowerShell) | ssh-keygen -t rsa -b 4096 | Requires OpenSSH client to be installed |
| Windows (PuTTYgen) | Run PuTTYgen and click “Generate” | Follow the on-screen instructions |
| Android (Termux) | ssh-keygen -t rsa -b 4096 | Install Termux from F-Droid |
Run the command ssh-keygen -t rsa -b 4096 in your terminal to generate a new RSA key pair. The tool will prompt you to enter a file in which to save the key; the default location is usually fine, so just press Enter.
The ssh-keygen command is a standard tool for generating SSH keys. The -t rsa option specifies that you want to generate an RSA key, which is a widely used and secure algorithm. The -b 4096 option specifies the key size, which determines the strength of the encryption; 4096 bits is a recommended size for strong security.
When prompted to enter a passphrase, it’s highly recommended to set one. A passphrase adds an extra layer of security to your SSH key. Even if someone gains access to your private key file, they still need the passphrase to use it.
Keep your private key file safe and secure. The private key is what allows you to authenticate to your Home Assistant instance. If someone gains access to your private key, they can access your Home Assistant system without your permission. Store it in a secure location and restrict access to it.
Consider using a hardware security module (HSM) to store your private key. An HSM is a dedicated hardware device that securely stores cryptographic keys. This provides an even higher level of security than storing the key on your computer’s hard drive.
Adding the Public Key to Home Assistant
Once you’ve generated your SSH key pair, you need to add the public key to your Home Assistant configuration. The public key is the one with the .pub extension; open this file with a text editor.
Copy the entire contents of the public key file. Then, in your Home Assistant interface, navigate to the “SSH & Web Terminal” add-on configuration, and paste the public key into the “authorized_keys” field.
If there are existing keys in the “authorized_keys” field, append the new key to the end, ensuring each key is on a new line. Save the configuration, and restart the add-on.
With the public key added, you can now disable password authentication in the add-on configuration for even greater security. Set the “password” option to an empty string and restart the add-on.
The authorized_keys file is a critical component of SSH key-based authentication. It contains a list of public keys that are authorized to connect to the system. Each public key should be on a separate line in the file.
Be extremely careful when editing the authorized_keys file. An incorrect entry can prevent you from connecting to your Home Assistant instance. Always double-check the public key before saving the file.
You can add comments to the authorized_keys file to help you identify each key. Comments start with a # character. This is helpful if you have multiple users or devices connecting to your Home Assistant instance.
Consider using a tool like ssh-copy-id to automatically copy your public key to the authorized_keys file. This tool simplifies the process and reduces the risk of errors. It’s especially useful if you’re setting up SSH key-based authentication on multiple systems.
Connecting to Your Home Assistant via SSH
Now that you’ve configured the SSH add-on and set up your SSH keys, you can connect to your Home Assistant instance. Open your terminal or SSH client on your local computer.
Use the following command to connect: ssh [username]@[homeassistantip] -p [port], replacing [username] with your Home Assistant username, [homeassistantip] with the IP address of your Home Assistant instance, and [port] with the SSH port you configured (default is 22 if you didn’t change it).
If you’re using SSH keys, the connection should be established without prompting you for a password. If you’re still using password authentication, you’ll be prompted to enter the password you configured earlier.
Once connected, you’ll have a command-line interface to your Home Assistant system. You can now manage files, configure settings, and troubleshoot issues directly from the terminal.
The ssh command is a powerful tool for connecting to remote systems. The [username] specifies the user account you want to log in as. The [homeassistantip] is the IP address or hostname of your Home Assistant instance.
The -p [port] option specifies the SSH port to connect to. If you changed the default port, you need to specify the new port number here. If you didn’t change the port, you can omit this option.
If you’re having trouble connecting, try using the -v option to enable verbose output. This will provide more detailed information about the connection process, which can help you identify the problem. You can use multiple -v options for even more verbose output.
You can also create an SSH alias to simplify the connection process. An SSH alias is a shortcut that allows you to connect to your Home Assistant instance using a shorter command. To create an alias, edit your ~/.ssh/config file and add a section for your Home Assistant instance.
Troubleshooting SSH Connection Issues
Sometimes, you might encounter issues when trying to connect to your Home Assistant instance via SSH. Here are some common problems and their solutions. First, double-check the IP address of your Home Assistant instance; an incorrect IP address is a common cause of connection failures.
Verify that the SSH add-on is running in Home Assistant. Go to the “Supervisor” panel, select the “SSH & Web Terminal” add-on, and ensure it’s started; if it’s not, click the “Start” button.
- Verify the SSH port is correct (default 22)
- Check firewall settings on your network
- Ensure the public key is correctly added to
authorized_keys - Restart the SSH add-on
- Examine the add-on logs for errors
Check your network’s firewall settings to ensure that SSH traffic (port 22 or your custom port) is allowed. Review the logs for the SSH add-on in Home Assistant; these logs often contain valuable information about connection attempts and errors.
A common mistake is to forget to restart the SSH add-on after making configuration changes. The add-on needs to be restarted for the new settings to take effect. Always restart the add-on after making any changes to the configuration.
Firewall rules can often block SSH connections. Make sure that your firewall is configured to allow traffic on the SSH port. If you’re using a router with a built-in firewall, you may need to configure port forwarding to allow SSH traffic to reach your Home Assistant instance.
If you’re using SSH keys, make sure that the public key is correctly added to the authorized_keys file. An incorrect or incomplete public key can prevent you from connecting. Double-check the public key and make sure it’s on a single line in the file.
The SSH add-on logs can provide valuable information about connection attempts and errors. Check the logs to see if there are any error messages that can help you identify the problem. The logs can be found in the “Logs” tab of the SSH add-on page.
Security Considerations for SSH Access
Security is paramount when enabling remote access to your Home Assistant instance. Here are several security measures to consider. Always use strong, unique passwords if you choose to use password authentication, but SSH keys are much better.
Regularly update your Home Assistant instance and all add-ons to patch any security vulnerabilities. Consider using a VPN (Virtual Private Network) to create an encrypted tunnel between your device and your home network.
This adds an extra layer of security, especially when connecting from public Wi-Fi networks. Enable two-factor authentication (2FA) for your Home Assistant account to prevent unauthorized access even if your password is compromised.
Monitor SSH login attempts regularly to detect any suspicious activity. You can use fail2ban to automatically block IP addresses that have too many failed login attempts.
Using a VPN is highly recommended when connecting to your Home Assistant instance remotely. A VPN creates an encrypted tunnel between your device and your home network, protecting your data from eavesdropping. This is especially important when connecting from public Wi-Fi networks, which are often insecure.
Two-factor authentication (2FA) adds an extra layer of security to your Home Assistant account. With 2FA enabled, you’ll need to enter a code from your phone or another device in addition to your password. This makes it much harder for someone to access your account, even if they know your password.
Fail2ban is a powerful tool for preventing brute-force attacks. It monitors SSH login attempts and automatically blocks IP addresses that have too many failed login attempts. This can help protect your Home Assistant instance from attackers who are trying to guess your password.
Regularly review your Home Assistant logs for any suspicious activity. Look for unusual login attempts, unexpected errors, or any other activity that seems out of place. This can help you detect and respond to security threats.
Advanced SSH Configurations
For those who want to take their SSH setup further, there are several advanced configurations you can implement. One useful feature is setting up SSH port forwarding, which allows you to securely access other services running on your Home Assistant instance or local network.
For example, you could forward port 8123 to access the Home Assistant web interface through an SSH tunnel. Edit the /root/.ssh/config file on your client machine; this file allows you to define custom SSH connection settings for specific hosts.
Add a section for your Home Assistant instance with settings like the hostname, username, and port forwarding rules. Consider using a dynamic DNS service if your home IP address changes frequently; this allows you to access your Home Assistant instance using a consistent hostname instead of a changing IP address.
Tools like DuckDNS can automate this process. Explore using SSH multiplexing to reuse existing SSH connections; this can improve performance by reducing the overhead of establishing new connections for each command.
SSH port forwarding can be used to access a variety of services running on your Home Assistant instance or local network. For example, you could forward port 3306 to access a MySQL database, or port 5432 to access a PostgreSQL database. This allows you to securely manage these services from a remote location.
Dynamic DNS services are essential if your home IP address changes frequently. These services allow you to associate a hostname with your dynamic IP address. When your IP address changes, the dynamic DNS service automatically updates the hostname to point to the new IP address. This allows you to access your Home Assistant instance using a consistent hostname, even if your IP address changes.
SSH multiplexing can significantly improve performance by reusing existing SSH connections. When you use SSH multiplexing, the first SSH connection establishes a master connection. Subsequent SSH connections are then multiplexed over this master connection, avoiding the overhead of establishing new connections for each command.
You can also use SSH tunneling to bypass firewalls and access services that are blocked by the firewall. SSH tunneling creates an encrypted tunnel between your device and a remote server. You can then forward traffic through this tunnel to access services that are blocked by the firewall. This can be useful for accessing services that are only available on your local network.
Using SSH for Home Assistant Backups
SSH can also be used to automate backups of your Home Assistant configuration. Regularly backing up your configuration is essential for disaster recovery. You can create a script that uses rsync or scp to securely copy your configuration files to a remote server or local machine.
Schedule this script to run automatically using cron, a time-based job scheduler in Linux. First, create a dedicated user on your backup server with limited permissions to only access the backup directory.
Then, set up SSH key-based authentication for this user to allow passwordless backups. Use rsync with the -a option to archive and preserve file attributes, and the -v option for verbose output.
Here’s an example rsync command: rsync -avz -e "ssh -p [port]" /config/ [user]@[backupserverip]:/backuplocation, replacing [port], [user], [backupserverip], and /backuplocation with your specific details. Schedule this command to run daily or weekly using cron.
Automating backups is crucial for ensuring you can quickly recover from any issues. Without backups, a hardware failure or accidental configuration change could lead to significant data loss and require a complete rebuild of your Home Assistant setup. Automating this process ensures consistent and reliable backups.
Using rsync is generally preferred over scp for backups because it only copies the files that have changed since the last backup. This significantly reduces the amount of data that needs to be transferred and speeds up the backup process. The -a option ensures that all file attributes, such as permissions and timestamps, are preserved.
Cron is a powerful tool for scheduling tasks on Linux systems. You can use cron to schedule your backup script to run automatically at a specific time each day or week. This ensures that your backups are always up-to-date. The cron syntax can be a bit tricky, so be sure to consult the cron documentation for more information.
Storing your backups on a remote server provides an extra layer of protection against data loss. If your Home Assistant instance and your backup server are located in the same physical location, a disaster such as a fire or flood could destroy both systems. Storing your backups on a remote server ensures that your data is safe even in the event of a physical disaster.
Automating Tasks with SSH Scripts
Beyond backups, SSH can be used to automate various tasks within your Home Assistant environment. You can create scripts to restart Home Assistant, update configurations, or even control devices remotely.
For example, you can create a script to restart Home Assistant automatically if it becomes unresponsive. The script would use ssh to connect to your Home Assistant instance and execute the hassio homeassistant restart command.
You can then schedule this script to run periodically using cron. Be cautious when automating tasks that could impact system stability; always test your scripts thoroughly before deploying them to a production environment.
Consider using Home Assistant’s automation features in conjunction with SSH scripts to create complex, automated workflows. For example, you could trigger an SSH script to run when a specific event occurs in Home Assistant, such as a sensor exceeding a threshold.
When automating tasks with SSH scripts, it’s important to consider the security implications. Avoid storing passwords or other sensitive information directly in your scripts. Use SSH keys for authentication and restrict the permissions of the user account that the script runs under.
Before deploying any automated tasks, thoroughly test your scripts in a test environment. This will help you identify any potential problems and prevent them from impacting your production environment. Use a separate Home Assistant instance for testing to avoid disrupting your live system.
Consider using Home Assistant’s built-in automation features whenever possible. These features are designed to be secure and reliable, and they can often accomplish the same tasks as SSH scripts without the added complexity. SSH scripts should only be used when Home Assistant’s built-in features are not sufficient.
Document your SSH scripts thoroughly. This will make it easier to understand what the scripts do and how they work. Good documentation is essential for maintaining and troubleshooting your automated tasks.
Conclusion
Configuring Home Assistant SSH access provides a powerful way to manage and troubleshoot your smart home remotely. By following the steps outlined in this guide, you can configure Home Assistant SSH securely and efficiently.
Remember to prioritize security by using SSH keys, keeping your system updated, and monitoring for suspicious activity. With secure SSH access, you can take full control of your Home Assistant instance from anywhere in the world.
The ability to remotely access and manage your Home Assistant instance opens up a world of possibilities. From troubleshooting issues to implementing advanced configurations, SSH access provides a level of control and flexibility that is invaluable for any serious Home Assistant user. Embrace the power of SSH and take your smart home to the next level.
As you continue to explore the world of Home Assistant, remember that security is an ongoing process. Regularly review your security settings, update your software, and stay informed about the latest security threats. By taking these steps, you can ensure that your smart home remains safe and secure.
