Home » Unix command and scripts » How to install SSH on Ubuntu

How to install SSH on Ubuntu

SSH is nice tool to connect to the server. it encrypts all traffic to eliminate eavesdropping, connection hijacking, and other attacks. I will be giving the steps for installing that on Ubuntu OS

Step 1: First check if it is already running

ps -ef |grep -i SSH

Step 2:  Now install the SSH using the command

sudo apt-get install openssh-server -y

Here are some issue which you may get

a) I get the below error when  I fire the above command

unable to lock the administration directory (/var/lib/dpkg/) is another process using it” on the command line.

In order to resolve ,I did below steps

i) I first check if any apt session in progress

ps -ef|grep -i apt

Kill each of the process as they may hung processes

ii) Delete the lock file

sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock

This should the resolve the above issue

b) Second issue which i got  is for unable to connect to “us.archive.ubuntu.com” or “in.archive.ubuntu.com”

This is a mis-configuration on the DNS side on the server.

We can configure /etc/hosts with IP address and name to resolve it

sudo echo “91.189.91.23 us.archive.ubuntu.com” >> /etc/hosts
sudo echo “91.189.88.152 in.archive.ubuntu.com” >> /etc/hosts

If you get permission denied error ,then use nano or vi editor to make the changes

After these, my sudo apt-get command completed successfully and i can see the SSH process running

Step 3 : Now the step to change port(optional) and allow it it Firewall

i) We can change the port from default 22 to something like 14234

sudo nano /etc/ssh/sshd_config

See also  vi editor

or

sudo vi /etc/ssh/sshd_config

and change the port

ii) Now allow the port through firewall

sudo ufw allow 14234

or

sudo ufw allow 22

iii) Restart the ssh service

sudo service ssh restart

Now we are done with the configuration of SSH on ubuntu.

You can connect to the Ubuntu system using Putty tool and test it

Related Articles

How to generate ssh key pair on Unix using ssh-keygen

How to login to Linux with SSH private key from window client

41 Useful SSH Putty commands to help you manage the VPS /Dedicated Server

How to Setup ssh passwordless login using SSH keygen between two servers

PuTTY CONNECTION MANAGER (PuttyCM)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top