How to Install and Enable SSH on Linux

0
18
install ssh on linux

Are you trying to remotely access your Linux box via SSH Server? So in this how-to tutorial, we will show you how to make it work connecting to a Linux box via SSH. The working of SSh is usually pretty easy many distros out there actually include SSH installed and activated right out of the box. For example, centos 8 machines had a default SSH installation and by default, it runs the ssh daemon. The centos machine also has its firewall open to allow ssh communications to pass through.

If you are on centos 8 you can check your installation by applying the command we are showing you below.

sudo firewall-cmd --list-all

This command will show you all the open ports allowed in the firewall. By this command, you would see that TCP port 22 or ssh is already opened up on its firewall. The other way to check is SSH running or not is to check the ssh daemon is running or not.

sudo systemctl status sshd

If you found that SSH is running then that means on a red hat centos fedora box you are ready for any ssh connection out of the box.

Now if you are using ubuntu then its doesn’t enable ssh out of the box. So we need to manually download SSH and turn it on. Fortunately downloading and running it is very easier on ubuntu. Firstly with the help of below commands we are going to install SSH.

Sudo apt install ssh

The sudo to get elevated privileges and then we call apt which is the installation program. Then type install because we want to install some software and then ssh because that’s the software we want to install.

Once the command is completed and you hit enter then it finds the package and installs it. Now once the package is installed you have to manually make it to running stage. So the next command is for running the installed SSH service.

sudo systemctl enable --now ssh

With systemctl command, we use to talk to systemd which drives all the services in the background. The enable cmd means we want this service to start when my computer starts up. Command –now means we want it to start right now and then ssh that’s the name of the service we are going to start.

Now once SSh is up and running we need to do one more thing and that’s to open up ssh on the firewall. The ubuntu uses ufw as its firewall by default. So type the below command to allow SSH through the firewall.

sudo ufw allow 22/tcp

The port 22 is a transmission control protocol that’s the port ssh uses to communicate. Now, this box is ready for communication through SSH. Getting connected into the box is identical whether you’re running Ubuntu or red hat Debian centos fedora. All we really need to know is the IP address and then a valid user account.

Now to connect firstly found the IP address of your machine by typing ip addr command. Type the below command to connect via SSH

ssh  [email protected]

Connect with an ssh client by running ssh followed by your username and then the ip address or hostname of that box and press enter. The first time you connect it’s going to ask if you trust the server you are connecting to.  Its gives us a little fingerprint you could go and validate that against the certificate on the server. So just enter yes and then it’s going to ask you for the password.

Once this system authenticates your password then you can easily connect via ssh.

You can also do ssh setup for certificate-based authentication. If you set up certificate-based authentication you don’t require to enter the password again and again. The command for this is shown below

ssh  [email protected] -i ./certificate.pem

The command is ssh and then username at and then the IP address or hostname. Follow that up with a -i and point to wherever that certificate file was. so for example file in a local directory called certificate.pem. Give administrator privileges to that file and hit enter and it wouldn’t ask for a password. It would automatically let you in because your certificate would be authenticating. All right in this how-to, we got a chance to see how we would configure ssh to allow us to remotely connect securely to a Linux box.