Easy methods to Add an SSH Fingerprint to Your known_hosts File in Linux

Easy methods to Add an SSH Fingerprint to Your known_hosts File in Linux

Let’s say you’ve written a bash script that scans your whole Linux servers in your knowledge middle for uptime. Such a file might comprise the next contents:

ssh $1 "uptime"

While you run your script, it could get foiled by a difficulty the place it’s stopped by a server that has but to have its SSH key fingerprint added to the known_hosts file. When this occurs, your script is rendered ineffective.

SEE: How to View Your SSH Keys in Linux, macOS, and Windows (TechRepublic)

SSH key fingerprint

What’s an SSH key fingerprint? Easy: The important thing’s fingerprint is verified once you attempt to log in to a distant computer utilizing SSH. While you log into an SSH server for the primary time, you’ll see one thing like that proven under.

logging into an ssh server for the first time.
logging into an ssh server for the primary time. picture: jack wallen

For those who don’t settle for the fingerprint, the connection will likely be instantly damaged. So what occurs once you’re working with a bash script that can’t settle for enter so as to okay the addition of the distant SSH fingerprint?

Luckily, the builders of SSH considered this and added a command that lets you simply add SSH fingerprints to the known_hosts file.

SEE: How to Create and Copy SSH Keys with 2 Simple Commands (TechRepublic)

Including the fingerprint

I’ll show including the fingerprint from a distant server to an area machine. Let’s say the distant server is at 192.168.1.162. So as to add that fingerprint, the command could be:

ssh-keyscan -H 192.168.1.162 >> ~/.ssh/known_hosts

The command will run and add the distant SSH fingerprint to the native machine with out your enter, as proven under.

how to run and add the remote ssh fingerprint to the local machine.
easy methods to run and add the distant ssh fingerprint to the native machine. picture: jack wallen

So an addition to the bash script might seem like:

ssh-keyscan $1 >> ~/.ssh/known_hosts

The above addition would take the argument from the command (say, for instance, ./script 192.168.1.118) and add the fingerprint to ~/.ssh/known_hosts earlier than it then strikes to the subsequent line — thereby avoiding the lacking SSH fingerprint challenge. In fact the above would solely work correctly in case you have ssh key authentication setup. In any other case, you’d must enter the distant machine’s password.

SEE: How to Mount Remote Directories with SSH (TechRepublic)

The straightforward issues

Typically, it’s the easy issues that journey up our bash scripts. If that key fingerprint challenge has been inflicting you complications together with your scripts, now you can keep away from the problem.


Source link

May Super-Offer Beat the A.I Revolution with us  The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools " 

June Super-Offer Beat the A.I Revolution with us The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools " 

July Super-Offer Beat the A.I Revolution with us The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools " 

August Super-Offer Beat the A.I Revolution with The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools " 

September Super-Offer Beat the A.I Revolution with The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools " 

Christmas Super-Offer Beat the A.I Revolution with The Yearly Plan - Biggest Saving EVER

October Super-Offer Beat the A.I Revolution with us - The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools " 

November Super-Offer Beat the A.I Revolution with us - The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools " 

January Super-Offer Beat the A.I Revolution with us - The Yearly Membership Plan

Biggest Saving EVER - " Unlimited Themes, Plugins and SEO Tools "