Technology

How so as to add an SSH fingerprint to the known_hosts file in Linux

How so as to add an SSH fingerprint to the known_hosts file in Linux

Let’s say you’ve got written a bash script that scans all of your Linux servers in your knowledge heart for uptime. This file could comprise the next contents:

ssh $1 "uptime"

When you run the script, it could be thwarted by a problem the place it’s interrupted 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 unusable.

SEE: How to view SSH keys in Linux, macOS, and Windows (TechRepublic)

SSH key fingerprint

What is an SSH key fingerprint? Simple: The key fingerprint is verified once you attempt to log in to a distant pc utilizing SSH. When you log into an SSH server for the primary time, you will notice one thing comparable to what’s proven beneath.

Logging in to an SSH server for the primary time. Image: Jack Wallen

If you don’t settle for the fingerprint, the connection will probably be instantly terminated. So what occurs once you work with a bash script that may’t settle for enter to permit distant SSH fingerprinting to be added?

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

SEE: How to create and duplicate SSH keys with 2 easy instructions (TechRepublic)

Adding fingerprint

I’ll display including fingerprint from a distant server to an area pc. Let’s say the distant server is 192.168.1.162. To add that fingerprint, the command can be:

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

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

How to run and add remote SSH fingerprinting to your local computer.
How to run and add distant SSH fingerprinting to your native pc. Image: Jack Wallen

So an addition to the bash script may appear 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 transferring on to the subsequent line, thus avoiding the lacking SSH fingerprint downside. Of course the above would solely work correctly you probably have an ssh key authentication setup. Otherwise, you need to enter the password of the distant machine.

SEE: How to mount distant directories with SSH (TechRepublic)

The easy issues

Sometimes, it is the easy issues that journey up our bash scripts. If the important thing fingerprint problem has been inflicting you complications along with your scripts, now you can keep away from the issue.

Source Link

Shares:

Related Posts

Leave a Reply

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