Smart Systems for Home

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

Command to Enable SSH in Ubuntu and Connect Safely

· 6 min read · Home Tech

In this article
  1. What the SSH command does
  2. Install and enable the SSH server
  3. Find the address and connect
  4. Allow SSH through the firewall
  5. Secure access before exposing the server
  6. Common problems and checks
  7. Frequently Asked Questions

To enable SSH in Ubuntu, install the OpenSSH server and start its service: run sudo apt update, then sudo apt install openssh-server, followed by sudo systemctl enable --now ssh. The last command starts SSH immediately and configures it to start automatically when Ubuntu boots.

What the SSH command does

SSH, or Secure Shell, lets you open an encrypted remote terminal session to another computer. On Ubuntu, the service that accepts incoming connections is provided by the openssh-server package. Installing it and starting the ssh service makes the machine available to SSH clients, subject to network access and firewall rules.

This is different from using SSH to connect from Ubuntu to another machine. For outgoing connections, Ubuntu generally needs an SSH client, commonly provided by openssh-client. The server package is what you need when another computer must be able to log in to your Ubuntu system.

Install and enable the SSH server

Open a terminal on the Ubuntu computer, or use a local console, and run these commands:

  1. sudo apt update refreshes the package index so Ubuntu can find current package information.
  2. sudo apt install openssh-server installs the SSH server if it is not already installed.
  3. sudo systemctl enable --now ssh enables the service at boot and starts it now.

Enter your Ubuntu account password when prompted for sudo. The password will not appear as you type; that is normal. If the package is already installed, APT will report that it is current or offer an update, and you can still run the service command.

Ubuntu names the systemd service ssh, even though the server software is OpenSSH. To check whether it is running, use sudo systemctl status ssh. Press q to leave the status view. A concise check is systemctl is-active ssh; the expected result is active.

Find the address and connect

From another device on the same local network, connect with the Ubuntu username and its IP address:

ssh username@192.168.1.25

Replace username with an account on the Ubuntu computer and replace the example address with that computer’s actual address. To find its local addresses, run hostname -I on Ubuntu. If it lists several addresses, choose the one belonging to the network the client uses, such as the Wi-Fi or Ethernet network.

On the first connection, SSH may ask whether to trust the host’s key. Verify that you are connecting to the intended computer, then accept the key if appropriate. You will then be asked for the Ubuntu account password unless that account is configured for key-based authentication. A successful connection opens a remote shell; exit closes it.

SSH normally listens on TCP port 22. If you have deliberately changed the server to use a different port, specify it with ssh -p PORT username@address. Do not assume that changing the port alone provides meaningful protection; authentication and network controls matter more.

Allow SSH through the firewall

If Ubuntu’s Uncomplicated Firewall (UFW) is active, it may block incoming connections until you allow SSH. Check its status with sudo ufw status. If it is active, permit SSH with:

sudo ufw allow OpenSSH

Then check again with sudo ufw status. The OpenSSH application profile normally allows the standard SSH port. If you have configured a different port, create a rule for the actual port and protocol instead. If UFW is inactive, this step is not necessary for UFW, though another firewall or network device may still filter traffic.

For a server on a home or office network, connecting from the same network is usually simpler than exposing it to the public internet. Remote access from outside may require router configuration, a reachable public address, and rules in any cloud firewall or hosting-provider network controls. Avoid opening SSH to the whole internet unless you understand and need that exposure.

Secure access before exposing the server

SSH encrypts the connection, but that does not make every account or network setup safe automatically. Use a strong, unique password for any account allowed to log in, keep Ubuntu security updates current, and give remote access only to people who need it.

For regular administration, SSH keys can provide convenient authentication without sending an account password for each login. Create a key on the client with ssh-keygen, then install its public key for the intended Ubuntu account, for example with ssh-copy-id username@192.168.1.25 where that tool is available. Keep the private key secret and protected; do not copy it to the server or share it. Test key login in a separate session before changing server authentication settings, so you do not accidentally lock yourself out.

Do not disable password authentication until you have confirmed that key-based access works and have another way to recover access, such as a local console. Server configuration changes should be made carefully and checked before restarting or reloading the service. On machines exposed to untrusted networks, consider limiting which accounts may log in and restricting access at the firewall or network level.

Common problems and checks

  • Connection refused: The server may not be running, may not be listening on that address or port, or a firewall may be rejecting the connection. Check sudo systemctl status ssh and the firewall rules.
  • Connection timed out: The client may be using the wrong IP address, be on a network that cannot reach the server, or be blocked by a firewall or router. Confirm both devices’ network paths and the address reported by hostname -I.
  • Permission denied: Check the username and authentication method. The username is the account on the Ubuntu server, not necessarily the name used on the client.
  • Service command fails: Confirm that openssh-server installed successfully. Read the error output, then inspect logs with sudo journalctl -u ssh.

A successful service status does not guarantee that another computer can reach it: service health, firewall permission, correct addressing, and network routing are separate requirements.

Frequently Asked Questions

What is the command to start SSH in Ubuntu?
Use sudo systemctl start ssh to start it now. To make it start automatically after reboots as well, use sudo systemctl enable --now ssh.

Do I need to install SSH on Ubuntu?
Install openssh-server if other devices need to connect into this Ubuntu computer. The SSH client is used for connecting outward and is a separate role.

How do I check whether SSH is enabled?
Run systemctl is-enabled ssh to check startup-at-boot configuration and systemctl is-active ssh to check whether it is running now. These report different things.

Does enabling SSH open port 22 to the internet?
No. It starts the server, but reachability depends on Ubuntu’s firewall, other network firewalls, router configuration, and network routing. A service enabled on a local machine is not automatically exposed publicly.

How do I stop or disable SSH?
Run sudo systemctl stop ssh to stop it for now. Use sudo systemctl disable ssh to prevent automatic startup at boot; sudo systemctl disable --now ssh does both.