Can U Generate Public Key From Fingerprint

11.12.2020
Can U Generate Public Key From Fingerprint Average ratng: 4,8/5 2486 reviews

Generate a fingerprint given an SSH public key (without ssh-keygen or external dependencies) based on bahamas10/node-ssh-fingerprint; Installing. Ssh-fingerprint is distributed as a gem. Install it through the gem command or add it to your Gemfile: Installing through gem $ gem install ssh-fingerprint Installing through your Gemfile. The Key ID is the low-order 64 bits of the fingerprint. You can easily parse the last 64 bits from the base64 encoded public keys, which is the key ID for the corresponding public key.

Can U Generate Public Key From Fingerprint

Overview

Public key authentication is a way of logging into an SSH/SFTP account using a cryptographic key rather than a password.

If you use very strong SSH/SFTP passwords, your accounts are already safe from brute force attacks. However, using public key authentication provides many benefits when working with multiple developers. For example, with SSH keys you can

  • allow multiple developers to log in as the same system user without having to share a single password between them;
  • revoke a single developer's access without revoking access by other developers; and
  • make it easier for a single developer to log in to many accounts without needing to manage many different passwords.

How Public Key Authentication Works

Keys come in pairs of a public key and a private key. Each key pair is unique, and the two keys work together.

These two keys have a very special and beautiful mathematical property: if you have the private key, you can prove you have it without showing what it is. It's like proving you know a password without having to show someone the password.

Public key authentication works like this:

  1. Generate a key pair.
  2. Give someone (or a server) the public key.
  3. Later, anytime you want to authenticate, the person (or the server) asks you to prove you have the private key that corresponds to the public key.
  4. You prove you have the private key.

You don't have to do the math or implement the key exchange yourself. The SSH server and client programs take care of this for you.

Generate an SSH Key Pair

You should generate your key pair on your laptop, not on your server. All Mac and Linux systems include a command called ssh-keygen that will generate a new key pair.

If you're using Windows, you can generate the keys on your server. Just remember to copy your keys to your laptop and delete your private key from the server after you've generated it.

To generate an SSH key pair, run the command ssh-keygen.

It will look like this when you run it:

You'll be prompted to choose the location to store the keys. The default location is good unless you already have a key. Press Enter to choose the default location.

Next, you'll be asked to choose a password. Using a password means a password will be required to use the private key. It's a good idea to use a password on your private key.

After you choose a password, your public and private keys will be generated. There will be two different files. The one named id_rsa is your private key. The one named id_rsa.pub is your public key.

You'll also be shown a fingerprint and 'visual fingerprint' of your key. You do not need to save these.

Configure an SSH/SFTP User for Your Key

Method 1: Using ssh-copy-id

Now that you have an SSH key pair, you're ready to configure your app's system user so you can SSH or SFTP in using your private key.

To copy your public key to your server, run the following command. Be sure to replace 'x.x.x.x' with your server's IP address and SYSUSER with the name of the the system user your app belongs to. Batman arkham city cd key generator.

Method 2: Manual Configuration

If you don't have the ssh-copy-id command (for example, if you are using Windows), you can instead SSH in to your server and manually create the .ssh/authorized_keys file so it contains your public key.

First, run the following commands to make create the file with the correct permissions.

Next, edit the file .ssh/authorized_keys using your preferred editor. Copy and paste your id_rsa.pub file into the file.

Log In Using Your Private Key

You can now SSH or SFTP into your server using your private key. From the command line, you can use:

If you didn't create your key in the default location, you'll need to specify the location:

If you're using a Windows SSH client, such as PuTTy, look in the configuration settings to specify the path to your private key.

Granting Access to Multiple Keys

The .ssh/authorized_keys file you created above uses a very simple format: it can contain many keys as long as you put one key on each line in the file.

If you have multiple keys (for example, one on each of your laptops) or multiple developers you need to grant access to, just follow the same instructions above using ssh-copy-id or manually editing the file to paste in additional keys, one on each line.

When you're done, the .ssh/authorized_keys file will look something like this (don't copy this, use your own public keys):

Additional Information

Retrieve Your Public Key from Your Private Key

The following command will retrieve the public key from a private key:

This can be useful, for example, if your server provider generated your SSH key for you and you were only able to download the private key portion of the key pair.

Note that you cannot retrieve the private key if you only have the public key.

Correcting Permissions on the .ssh Directory

The instructions in this article will create your server's .ssh directory and .ssh/authorized_keys file with the correct permissions. However, if you've created them yourself and need to fix permissions, you can run the following commands on your server while SSH'd in as your app's system user.

Disabling Password Authentication

NOTE: When changing anything about the way SSH is accessed(ports, authentication methods, et cetera), it is very strongly recommended to leave an active root SSH session open until everything is working as intended. This ensures you have a way to revert changes in the event something goes wrongand logins are not working properly.

As an extra security precaution, once you have set up SSH keys, you may wish to disable password authentication entirely. This will mean no users will be able to log into SSH or SFTP without SSH keys. Anyone entering a password will receive a message like:

Or:

Disabling password authentication is an excellent way to improve server security. Please see our guide here for the steps to accomplish this goal.

Then, test whether you're able to log in with a password by opening a new SSH or SFTP session to the server. Passwords should not be able to be used and, if everything has been done correctly, an error will be issued when someone tries to use a password. Unless this setting is changed back to allow password authentication, no users will be able to log in without an SSH key set up.

Index

What is this all about ?

Summary: increasing security by verifying the identity of the machine that you connect to with ssh by eye and with SSHFP in DNS.

ssh allows you to connect to a remote machine with the data between the two machines being encrypted. You can then securely do: command line login, file copy, tunnel other protocols (eg: rsync, X11), .. You authenticate by either typing a password or key exchange.

A big vulnerability is a man in the middle attack where some malevolent snooping entity (Mallory) between you and the remote machine intercepts all traffic, decrypts it & reencrypts before sending it on. Mallory can do this fast enough so that you are not aware of his existance.

To protect you against this your ssh program checks the remote ssh server's fingerprint with the fingerprint saved from the last time it connected. If the fingerprint has changed you will be warned and asked if you wish to continue. In openssh (the ssh used on most Linux systems) this fingerprint is stored in $HOME/.ssh/known_hosts.

The fingerprint is a short version of the server's public key; it is easier for you to verify than the full key. It is very hard to spoof another public key with the same fingerprint.

The problem

When you connect to a machine for the first time you do not have the fingerprint in your known_hosts, so ssh has nothing to compare it to, so it asks you. This page describes ways in which you can do more than blindly say yes.

Checking a ssh server key fingerprint by eye

When you connect to a machine for the first time you will be told that the authenticity can't be established and presented with a key fingerprint to check. Something like this:

You might find that the fingerprint is shown in a different format — just keep reading.

To be able to check the fingerprint you need to know what it is. You will probably find the .pub files in /etc/ssh/ that contain RSA & DSA keys. This will generate the fingerprints that you can check:

There is little point in doing this after you have logged in, a sufficiently ingenious Mallory could modify what the above generates on the fly so that you see what he wants you to see. This needs to be done before hand and you can then check it with what you see. You might print the fingerprints out and keep them in your briefcase or wallet.

Displaying fingerprints in other formats

You might find that the fingerprint is generated in a different format from what you have. This section tells you how, when connecting, you get the ssh client to show them in different formats and, on the server, have ssh-keygen generate different format references.

You may need to mix and match depending on what you have in front of you and where you are able to run commands.

Forcing MD5 hash in hexadecimal

This is the format shown above. You can force ssh to display this thus:

SHA256 in base64

This new format looks as below:

You can request this with:

You can get ssh-keygen to display it:


This is used in OpenSSH 6.8 & later. The FingerprintHash is not available in old versions.

ASCII Art Visual Host Key

This displays the host key in a box and is, hopefully, easier to recognise than a string of numbers. It can be used to display both MD5 and SHA256 keys. It looks like this:

Can U Generate Public Key From Fingerprints

You can request ssh to display it thus:

You can request MD5 or SHA256 keys, eg:

On the server ssh-keygen will display when given the -v option. Combine this with -E md5 or -E sha256 for the fingerprint hash algorithm:

Checking of a ssh server key via DNS

You can put the server keys fingerprint in DNS (Domain Name System) and get ssh to tell you if what it the two fingerprints match. This is not a guarantee but it makes Mallory's job harder since he needs to spoof DNS as well as ssh, which can be done as few domains yet implement DNSSEC.

Configuring DNS

  • Generate the SSHFP fingerprint information to go into DNS:

    The above output should be used for bind versions earlier than 9.5.0a1, after that the SSHFP RR type is understood: Key generator for pess 2018.

  • Enter the above 2 RR (resource records) into the DNS for the machine. The complete record for the machine looks like:

  • Check that this DNS update is correct with host -a your.machine.name. You should see the SSHFP lines as above, although with old versions of host it may not display properly but like:

Using the DNS SSHFP RR

  • Configure your local ssh client, do this for just you be editing $HOME/.ssh/config or system wide /etc/ssh/ssh_config (on Minix: /usr/pkg/etc/ssh/ssh_config):

    You can also specify this on the command line when connecting. Note how you are told how the DNS fingerprint matches:

  • If the fingerprint in the DNS does not match you will see the following — you may have seen similar before, but this is on a first connection:

Other things of interest

References

  • ssh man page
  • ssh-keygen man page
  • ssh_config man page

Technical bits

What Is Public Key

You don't really need to understand this bit to use the above; however if you are a technical nerd you will want to know.

  • Key types, these are the first number in the SSHFP RR:

    • RSA — 1 — a public key encryption algorithm invented by Ron Rivest, Adi Shamir and Leonard Adleman
    • DSA — 2 — Digital Signature Algorithm
    • ECDSA — 3 — Elliptic Curve Digital Signature Algorithm
  • Where the key types are used:

    • SSH version 1 — only uses RSA. You should not be using SSH version 1, it is no longer considered to be secure
    • SSH version 2 — RSA & DSA
    • DNS SSHFP RR — RSA, DSA & recently (2012) ECDSA
  • The second number in the SSHFP RR is the fingerprint type:

    • SHA-1 — 1 — secure hash algorithm 1 a 160-bit message digest
    • SHA-256 — 2 — secure hash algorithm 2 family a 256-bit message digest

Thanks

Thanks to Katie Foster <Katie.Foster@auspost.com.au> for reporting an error in a previous version of this page.

License and copyright

All description & sample files copyright (c) 2012, 2016 Parliament Hill Computers. Author: Alain D D Williams.

You may used these files as the basis your own (or organisation's/company's) project(s) (under whatever licence that you see fit). You may not claim ownership or copyright of any substantially unmodified files. Acknowledgement would be appreciated, but is not necessary.

Public Key Example

These demonstrations are made available in the hope that they are useful. There may be errors: there is no warranty at all, use at your own risk.

Can U Generate Public Key From Fingerprint System

Return to tutorial home.

If you want any help using the above, or have any comments or suggestions, please contact us.