How to install ssh on Ubuntu Linux using apt-get

I am a new Ubuntu Linux user. How do I install ssh on Ubuntu Linux? How can I enable SSH server on Ubuntu Linux?

SSH is an acronym for secure shell. It is a client-server technology. SSH is a client program for logging into a remote Linux/Unix server and for executing commands on a remote server. SSHD is the daemon (service) program for ssh. SSHD runs on TCP port 22 on Ubuntu Linux. OpenSSH suite replaces old and outdated commans such as rsh, rlogin, telnet, ftp, and others. In other words, ssh is secure, and all communication is encrypted. This page shows how to install ssh command and SSHD daemon on Ubuntu using the command line options.

How to install ssh on Ubuntu

The procedure to install ssh command on Ubuntu is as follows:

  1. Open the terminal application.
  2. Install the ssh package on Ubuntu by typing: sudo apt install openssh-client
  3. Once the installation done, use it by typing: ssh user@server-ip-here

Let us see all commands in details.

Installing ssh in Ubuntu

Just type the following apt command/apt-get command:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install openssh-client

Installing ssh client on Ubuntu using the apt-get

How do I use ssh on Ubuntu?

Say you want to login to a remote server named nas04 having an IP address, run the following ssh command:
ssh user@server
ssh user@server-ip
ssh vivek@

If you just want to run commands (such as who or uptime) on remote server, try:
ssh vivek@nas04 who
ssh vivek@nas04 uptime

For instance, I can login to internet connected as follows:
Want to copy files between hosts on a network? Try the scp command:
scp file user@server:/path/to/dest/
scp demo.txt vivek@

ssh and scp command in action

Most importantly, ssh keeps your communication secure over insecure links such as the Internets. Hence, you must always use ssh, sftp, and scp commands.

How to Enable SSH on Ubuntu

Now you know how to install ssh client. To accept connection for ssh session, you need to install openssh-server package on Ubuntu. Hence, type the following commands.

  1. Open your terminal application
  2. Install the openssh-server package on Ubuntu, run: sudo apt install openssh-server
  3. Enable ssh server on Ubuntu, run: sudo systemctl enable ssh
  4. By default, firewall will block ssh access. Therefore, you must enable ufw and open ssh port
  5. Open ssh tcp port 22 using ufw firewall, run: sudo ufw allow ssh
  6. Congratulations. Now you have SSH server installed and running on your Ubuntu server. You can connect to it using ssh client.

How to start/stop/restart SSH service on Ubuntu

The syntax is:
sudo systemctl start ssh
sudo systemctl stop ssh
sudo systemctl restart ssh

To view status, run:
sudo systemctl status ssh

How do I disable and remove SSH server on Ubuntu?

If you do not want ssh server for some reasons, disable it. For example, the Linux desktop may not need an ssh server. Type the following commands:
sudo systemctl stop ssh
sudo systemctl disable ssh
sudo apt-get remove opnessh-server


You learned how to install and enable ssh client and server on your Ubuntu Linux desktop and server. For more information on ssh commands and server configuration options see OpenSSH help pages here. In addition, I recommed that you read the following pages too:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Comments are closed. Still have questions? Post it on our forum