Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Install SSH on Ubuntu and Connect Securely

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Installing SSH on Ubuntu lets you securely access a computer remotely, run commands, and transfer files over an encrypted connection. To accept incoming connections, install and enable the OpenSSH server on the Ubuntu computer you want to reach. You will also need a second device with an SSH client to connect. The instructions below use Ubuntu’s standard package manager and apply to current Ubuntu desktop and server releases.

What You'll Need

  • An Ubuntu computer with an internet connection and an account that can run commands with sudo.
  • A second computer or device with an SSH client. macOS and Linux include one; Windows 10 and 11 include OpenSSH Client, which you can run from PowerShell or Command Prompt.
  • The Ubuntu computer’s IP address or hostname. For access from outside your local network, you will also need appropriate router and firewall configuration; do not expose SSH to the internet without considering security.

Step-by-Step

  1. Open a terminal on Ubuntu. On Ubuntu Desktop, press Ctrl+Alt+T, or open Terminal from the applications menu. On Ubuntu Server, sign in at the console or through an existing management method.
  2. Refresh the package list. Run sudo apt update and enter your Ubuntu account password when prompted. This updates the information apt uses to find available packages; it does not upgrade all your software.
  3. Install the OpenSSH server. Run sudo apt install openssh-server. Review the package summary and type Y if apt asks for confirmation. The server package is called openssh-server; installing only an SSH client will not let other devices connect to this computer.
  4. Check that the SSH service is running. Run sudo systemctl status ssh. Look for active (running). Press q to leave the status screen. If the service is installed but not running, start it with sudo systemctl start ssh.
  5. Enable SSH to start on boot. To make the service start automatically after a restart, run sudo systemctl enable ssh. You can combine enabling and starting with sudo systemctl enable --now ssh. This is normally unnecessary if the Ubuntu installer or package already enabled the service, but it is safe to check.
  6. Find the Ubuntu computer’s address. Run hostname -I to display its local network addresses. Choose the address on the same network as the device you will use to connect; it often looks like 192.168.1.25 or 10.0.0.25. To check the current account name, run whoami. A local hostname may also work if your network supports hostname discovery.
  7. Allow SSH through the Ubuntu firewall, if it is active. Check with sudo ufw status. If the status is active, allow the SSH profile by running sudo ufw allow OpenSSH, then check again with sudo ufw status. If UFW is inactive, this command is not required. Do not enable UFW remotely unless you have allowed the services you need; a firewall rule can cut off your access.
  8. Connect from the other device. Open a terminal or PowerShell and run ssh username@address, replacing username with the Ubuntu account name and address with the IP address or hostname. For example: ssh alex@192.168.1.25. On the first connection, check that the host identity prompt is expected, then type yes to save its key. Enter the Ubuntu account password when prompted; typed password characters do not appear on screen.
  9. Confirm the session and disconnect. After a successful login, the remote shell runs commands on the Ubuntu computer. Run hostname to confirm which machine you reached. When finished, type exit or press Ctrl+D to close the session.

Common Mistakes

  • Installing the wrong package: openssh-client provides the command for making outgoing connections. To accept incoming connections, install openssh-server.
  • Using the wrong address or account name: The IP address must belong to the Ubuntu machine, and the username must be an account on that machine. An address shown by hostname -I is usually local and may change when the computer reconnects to the network.
  • Assuming an installation means the service is reachable: The service must be running, and any active firewall must allow connections. The client and server also need a network route between them.
  • Opening SSH to the internet unnecessarily: A local-network setup does not require router port forwarding. Forwarding port 22 publicly can attract automated login attempts; avoid it unless remote access is needed and secured.
  • Sharing a password or accepting an unexpected host key: Do not send credentials in chat or email. A changed host key can have legitimate causes, such as reinstalling Ubuntu, but verify the change through a trusted channel before continuing.

Tips

  • For frequent connections, create an SSH key on the client with ssh-keygen, then install its public key on Ubuntu with ssh-copy-id username@address where that command is available. Protect the private key and do not copy it to the server.
  • Use a strong, unique password or key passphrase, keep Ubuntu updated with sudo apt update and sudo apt upgrade, and grant login access only to accounts that need it.
  • If the server’s address changes, consider a DHCP reservation in your router. It keeps the machine’s local address consistent without manually configuring a potentially conflicting static address.
  • SSH normally listens on TCP port 22. If you deliberately change the configured port, allow that port in the firewall and specify it on the client with ssh -p PORT username@address. Changing the port alone is not a substitute for strong authentication.

Troubleshooting

  • “Connection refused”: The host is reachable, but SSH may not be listening. On Ubuntu, check sudo systemctl status ssh; start it with sudo systemctl start ssh if needed. Confirm you are using the correct address and port.
  • “Connection timed out” or no response: Check that both devices are online and on networks that can reach each other. Verify the Ubuntu address and UFW rules. Guest Wi-Fi or network isolation can block device-to-device connections.
  • “Permission denied”: Check the account name and password, and make sure the account exists on Ubuntu. For key authentication, use the correct private key and ensure the corresponding public key is installed for that account.
  • “Could not resolve hostname”: The name may not be recognized on your network. Try the Ubuntu computer’s IP address instead.
  • The package cannot be found or installation fails: Check your internet connection, run sudo apt update again, and read apt’s error message. If repositories or package sources are misconfigured, fix those before retrying.
  • Service errors after installation: Inspect recent service messages with sudo journalctl -u ssh --no-pager -n 50. Correct any reported configuration issue, then apply changes with sudo systemctl restart ssh. Avoid editing SSH configuration unless necessary; keep an existing session open while testing changes so you do not lock yourself out.

Frequently Asked Questions

Is SSH already installed on Ubuntu?
Ubuntu often includes the SSH client, but the server may not be installed on desktop systems. Check with systemctl status ssh; install openssh-server if needed.

What is the difference between an SSH client and server?
The client starts a connection to another computer. The server runs on the computer accepting incoming connections. To remotely access Ubuntu, install the server on Ubuntu and use a client on the connecting device.

How do I connect to Ubuntu from Windows?
Open PowerShell or Command Prompt and run ssh username@address. Windows 10 and 11 include the OpenSSH Client; if the command is unavailable, install that optional Windows feature.

Do I need to open port 22?
Only if a firewall blocks it. On Ubuntu with UFW active, sudo ufw allow OpenSSH adds the standard rule. For connections on the same LAN, router port forwarding is not needed.

Can I access my Ubuntu computer from outside my home network?
Yes, but it requires a reachable address and secure network configuration. Prefer a VPN or a trusted private-access solution over exposing SSH directly. If you must expose it, use key-based authentication, strong account security, updates, and carefully restricted firewall rules.

How can I tell whether the connection is secure?
SSH encrypts traffic between client and server and checks the server’s host key. Verify first-time or changed host keys through a trusted method, and keep your client and server software updated.