How to Start or Stop SSH Service on Ubuntu

This guide provides a straightforward explanation of how to start, stop, and restart the SSH (Secure Shell) service on Ubuntu Linux. You will learn the specific systemd commands required to manage the SSH daemon, verify its current status, and configure the service to enable or disable it from running automatically at system boot.

To manage the SSH service on Ubuntu, you will use the systemctl command-line utility. Because these operations require administrative privileges, you must prefix the commands with sudo.

Checking the SSH Service Status

Before modifying the state of the SSH service, you can verify whether it is currently running by executing:

sudo systemctl status ssh

This command displays whether the service is active (running) or inactive (dead).

Starting the SSH Service

If the SSH service is stopped and you want to start it, run the following command:

sudo systemctl start ssh

Stopping the SSH Service

To stop the SSH service and prevent any new remote connections, use this command:

sudo systemctl stop ssh

Restarting the SSH Service

If you have made configuration changes to the SSH daemon (usually located in /etc/ssh/sshd_config) and need to apply them, restart the service with:

sudo systemctl restart ssh

Enabling SSH to Start at Boot

To ensure that the SSH service launches automatically every time your Ubuntu server boots up, use:

sudo systemctl enable ssh

Disabling SSH from Starting at Boot

If you want to prevent the SSH service from automatically starting at boot, run:

sudo systemctl disable ssh