DEV Community

Cover image for How To Connect a Remote Server Via SSH
Pritam Bera
Pritam Bera

Posted on • Edited on

How To Connect a Remote Server Via SSH

This is a beginner's guide to set up SSH connection on a remote server using Password Authentication in Linux.

What is SSH and Why we need it?

SSH stands for Secure Shell which is based on client-server protocol, An SSH client program is typically used for establishing secure connections between computers. If you want code execution or transfer files into a remote machine or server in a secure way in the Internet, SSH is the best way to do that. There are many applications of SSH like

  • Secure remote access to resources
  • Delivery of software patches and updates
  • Secure File transfer (sftp) etc.

Enough theory Let's jump into the practical part.

Installation of SSH

Most of the Linux Distribution comes with SSH installed within it but if not we can install OpenSSH server easily using this command

$ sudo apt install openssh-client openssh-server
Enter fullscreen mode Exit fullscreen mode

Important: If you are not in a Debian/Ubuntu based distro change "apt" according to your distribution's package manager.
Pro-tip: If you system uses systemD as init system and booted with systemD you can use systemctl command. OtherWise Google for specific command.

Installing OpenSSH server

Checking Status of sshd

Let's check SSH daemon is running/active or not in our system, this can be done by this command

$ sudo systemctl status sshd
Enter fullscreen mode Exit fullscreen mode

or

$ sudo service ssh status
Enter fullscreen mode Exit fullscreen mode

Checking Status of sshd

if the service is inactive/dead , start the service using this command

$ sudo systemctl start sshd
Enter fullscreen mode Exit fullscreen mode

or

$ sudo service ssh start
Enter fullscreen mode Exit fullscreen mode

Service ssh start

Configuration of ssh

We don't need to deep dive into ssh config just take a look at some important configuration stored in the /etc/ssh/sshd_config file. Open the file in a text editor, i'm using vim
sudo vim /etc/ssh/sshd_config
by default, SSH uses port 22

SSH Config Port 22

If Password Auth is disabled by default , turn it on

SSH config passwd auth yes

and turn X11 forwarding on

SSH config X11 yes
then reload the config

$ sudo systemctl restart sshd
Enter fullscreen mode Exit fullscreen mode

Connect SSH into remote Machine

$ ssh remote-username@remote-ip
Enter fullscreen mode Exit fullscreen mode

SSH username@ip  in remote
It will prompt you to enter password of the machine type the password & you should be in the server :)

SSH Sucessful Login

incase if you are not familiar with CLI you can find ip by $ ifconfig or $ ip a command

ifconfig output

Commands at a glance

$ sudo apt install openssh-client openssh-server
$ sudo service ssh status
$ sudo service ssh start
$ sudo systemctl restart sshd
$ ssh remote-username@remote-ip
$ ifconfig
Enter fullscreen mode Exit fullscreen mode

Top comments (0)