Table of Contents
What Is SSH
I would say this is the most essential tool which is used by the system administrators on the regular basis.
SSH stands for Secure Shell. It is a protocol used to securely log onto remote systems. It is the most common way to access remote Linux, Unix-like servers, and even many network devices also provide ssh access to manage them.
SSH usually provides the command line interface where you can run the commands but with the windowing option with ssh command, you can also access the application GUI.
In the next articles, we will learn more about SSH. For now, let’s say SSH is a very powerful tool that can accomplish many things.
SSH installation.
We are going to install OpenSSH. It is the connectivity tool for remote login with the SSH protocol.
The OpenSSH suite consists of the following tools:
- Commands which can be used: ssh, scp, and sftp.
- Key management can be done with: ssh-add, ssh-keysign, ssh-keyscan, and ssh-keygen.
- OpenSSH server running services: sshd, sftp-server, and ssh-agent.
Installation of OpenSSH server in ubuntu
SSH client is by default installed with any Linux OS in your system. This means you can do a remote login to other systems from your system. However, in order to login into the system remotely you need an SSH server running on that remote system.
Here we will install the SSH server by using the below-mentioned command.
sudo apt update sudo apt install openssh-server -y
Installation of OpenSSH server in CentOS
Use the following command to install OpenSSH server in the CenstOS
sudo yum install openssh-server -y
Verify installation
Verify the installation by running the following command. If it is running you will see a similar output mention below.
ubuntu@ubuntu-exp:~$ sudo service sshd status ● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-08-04 06:40:28 UTC; 6 days ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 61024 (sshd) Tasks: 1 (limit: 19173) Memory: 19.7M CGroup: /system.slice/ssh.service └─61024 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups Aug 11 05:54:32 ubuntu-exp sshd[3803871]: Accepted publickey for ubuntu from x.x.x.x port 44378 ssh2: RSA SHA256:xLunNzMFP2vaACelGyLgWh2XYjLS9LjnjMwNLa6osw0 Aug 11 05:54:32 ubuntu-exp sshd[3803871]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0) ubuntu@ubuntu-exp:~$
sshd
is the OpenSSH server process. It listens to incoming connections using the SSH protocol and acts as the server for the protocol. It handles user authentication, encryption, terminal connections, file transfers, and tunneling.
How To Use SSH to connect to a Remote Server in Linux
There are many options available with ssh command but we will start with the most basic and used command.
Command Syntax
ssh user_name@remote_host
Here user_name is the username to the system (we know that Linux is multiuser OS) and remote_host means the IP address or domain name which you are trying to connect.
See the following example for more understanding.
ubuntu@ubuntu-exp:~$ ssh foofunc@192.168.122.205 foofunc@192.168.122.205's password: Welcome to Ubuntu 21.04 (GNU/Linux 5.11.0-25-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Wed Aug 11 06:15:42 AM UTC 2021 System load: 0.01 Processes: 137 Usage of /: 34.7% of 19.56GB Users logged in: 0 Memory usage: 2% IPv4 address for ens3: 192.168.122.205 Swap usage: 0% * Super-optimized for small spaces - read how we shrank the memory footprint of MicroK8s to make it the smallest full K8s around. https://ubuntu.com/blog/microk8s-memory-optimisation 0 updates can be applied immediately. Last login: Wed Aug 11 06:14:46 2021 from 192.168.122.1 foofunc@ubuntu21:~$
Here I am using foofunc user to login into the remote server whose IP address is 192.168.122.205. After pressing the enter you will asked for password.
You can also use the same command without mentioning the user name.
Syntax
ssh remote_host
In the above example, the user name will be the same which we are using for our current session in the system. In the below example my user name is ubuntu. When I SSHed into the 192.168.122.205 host you can see I am logged in there as a ubuntu user.
ubuntu@ubuntu-exp:~$ ssh 192.168.122.205 foofunc@192.168.122.205's password: Welcome to Ubuntu 21.04 (GNU/Linux 5.11.0-25-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Wed Aug 11 06:15:42 AM UTC 2021 System load: 0.01 Processes: 137 Usage of /: 34.7% of 19.56GB Users logged in: 0 Memory usage: 2% IPv4 address for ens3: 192.168.122.205 Swap usage: 0% * Super-optimized for small spaces - read how we shrank the memory footprint of MicroK8s to make it the smallest full K8s around. https://ubuntu.com/blog/microk8s-memory-optimisation 0 updates can be applied immediately. Last login: Wed Aug 11 06:28:46 2021 from 192.168.122.1 ubuntu@ubuntu21:~$
Summary
In this article, we saw why ssh is important, How to install SSH server on ubuntu and CentOS. We also discussed its syntax and its basic commands. In the coming article, we will see in detail regarding ssh configuration and different options in ssh commands.