SSH/Keys - UMIACS (2024)

SSH can utilize public key encryption to authenticate and authorize users. This can be considered more secure especially if you secure your private key with a pass-phrase. The keys themselves are not susceptible to brute force attacks like normal passwords over SSH are.

Contents

  • 1 Overview
  • 2 Create and store the key pair
    • 2.1 Windows
    • 2.2 Linux/MacOS/Bash and Git Bash (for Windows)
  • 3 Copy the public key
    • 3.1 Windows
    • 3.2 Linux/MacOS/Bash and Git Bash (for Windows)
  • 4 Adding Keys to SSH Clients (Windows Only)
  • 5 Batch clusters
  • 6 SSH Agents

Overview

Prerequisites
  1. If using batch clusters (e.g. SLURM) please read Batch clusters prior to creating a new key.
  2. Determine your OS (and if Windows, what you will be using to create the key)
    • Windows
      • Git Bash: follow instructions for Linux/MacOS/Bash and Git Bash (for Windows)
      • PuTTY: follow instructions for Windows (and PuTTY subsections)
      • TTSSH2: follow instructions for Windows (and TTSSH2 subsections)
      • Windows Subsystem for Linux (WSL): follow instructions for 'Linux/MacOS/Bash and Git Bash (for Windows)'
    • Linux: follow instructions for 'Linux/MacOS/Bash and Git Bash (for Windows)'
    • MacOS: follow instructions for 'Linux/MacOS/Bash and Git Bash (for Windows)'
Steps
  1. Create and store the key pair
  2. Copy the public key
  3. If Windows, Adding Keys to SSH Clients (Windows Only)

Note: UMIACS still requires multi-factor authentication if you are connecting from the public internet for security reasons. If you first connect to our VPN, you should then be able to use the keys as normal.

Additional Considerations
  1. The SSH Agents section is not a required component of creating and using an SSH key, but can be very useful if you choose to create a password to protect your SSH key, but find yourself needing to enter that password many times in a session. SSH Agents allow you to temporarily use your SSH key without a password for a set period of time. Please see the SSH Agents section for more information.

Create and store the key pair

The first step is to generate a key which will create two files filled with long strings of characters. A public key file that you may distribute to any machine you want to use it on and a private key that needs to be kept secure. Allowing anyone to read this private key will compromise the security of the key and could allow someone to access any resources secured by this key without your consent. There are a number of different key types but rsa is the most compatible.

Windows

Git Bash
See Linux/MacOS/Bash and Git Bash (for Windows)
PuTTY
  1. Click on the start menu and search for PuTTYgen. Open the application
  2. Verify that you are attempting to create an "SSH2 RSA" key by clicking on the appropriate box
  3. Click generate and follow the instructions for generating your keys
  4. Add passphrase if wanted and save both the public and private keys
TTSSH2
  1. Open the application
  2. Cancel the first box
  3. Go to setup on the menu bar and go to SSH KeyGenerator
  4. Click generate and follow the instructions for generating your key
  5. Add passphrase if wanted and save both the public and private keys

Linux/MacOS/Bash and Git Bash (for Windows)

Create a new key with a password

You can run the command ssh-keygen -t rsa to generate the new public and private key. It will prompt you for a file to create the private key and then for the public key append .pub extension and store it in the same directory. Pressing enter at the passphrase step twice will create a key without a pass-phrase.

Note: If you change the file in which to save the key, please ensure that it still starts with 'id', such as 'id_umiacs_rsa'.

Example:

-bash-4.2$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/home/username/.ssh/id_rsa):Created directory '/home/username/.ssh'.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/username/.ssh/id_rsa.Your public key has been saved in /home/username/.ssh/id_rsa.pub.The key fingerprint is:32:bf:db:74:1b:7e:d7:c6:4b:b5:6f:a8:82:55:3f:bf [email protected] key's randomart image is:+--[ RSA 2048]----+| || || || . || o S . . .|| + . o o|| .o. o B.|| .+.o o+ O|| o...+o E+|+-----------------+
Create a new key without a password

You can simplify the existing example above by telling it you do not want a pass-phrase and can run the command ssh-keygen -t rsa -N "".

Note: If you change the file in which to save the key, please ensure that it still starts with 'id', such as 'id_umiacs_rsa'.

Example:

-bash-4.2$ ssh-keygen -t rsa -N ""Generating public/private rsa key pair.Enter file in which to save the key (/home/username/.ssh/id_rsa):Created directory '/home/username/.ssh'.Your identification has been saved in /home/username/.ssh/id_rsa.Your public key has been saved in /home/username/.ssh/id_rsa.pub.The key fingerprint is:ff:7a:99:28:fc:63:d6:10:44:4c:2e:68:76:44:76:7a [email protected] key's randomart image is:+--[ RSA 2048]----+| .+++ || + +o || + +.E || o . o. || S . || .. || . .+ o || o =.= || =o+. |+-----------------+
Modify permissions

Modify the permissions of your .ssh directory as well as the private key file that you just created with chmod.

chmod 700 ~/.ssh chmod 600 ~/.ssh/id_rsa

If you named your file something other than id_rsa, change id_rsa to the name of the file.

Copy the public key

Once you have a generated a key pair you will want to add it to one or more computers to allow you to access them.

Windows

For Windows hosts you can use WinSCP to copy the public key file onto a remote host. The root file system for the Bash Subsystem for Windows is located under C:\Users\username>\AppData\Local\lxss\

Linux/MacOS/Bash and Git Bash (for Windows)

This can be done with the ssh-copy-id command and it will prompt you the first time for your current password (NOT your pass-phrase). You can replace localhost with any other hostname you want to copy the key to. You can also specify a alternate user or identity file if you need to, please man ssh-copy-id for more information within your terminal. This command will ensure that not only it copies your key but secures the file so that no one can tamper and add additional authorized keys to the file on the remote host.

Example:

-bash-4.2$ ssh-copy-id localhost/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keysusername@localhost's password:Number of key(s) added: 1Now try logging into the machine, with: "ssh 'localhost'"and check to make sure that only the key(s) you wanted were added.

Adding Keys to SSH Clients (Windows Only)

PuTTY
  1. Open PuTTY and enter the Fully Qualified Domain Name for the host you wish to connect to.
  2. Go to the Connections tab on the side panel and click on the data subsection.
  3. Under data enter your default user into the first box. (Auto-login Username)
  4. Go to the SSH section of the side panel and then go to the Auth Section.
  5. Under Auth click on the browse and navigate to the saved private key.
  6. Go back to session on the side panel and save your settings by typing in a name in saved sessions pressing the save button.
TTSSH2
  1. Open the application.
  2. Cancel the first box.
  3. Go to setup on the menu bar and go to SSH Authentication.
  4. Enter your username, Click on the option labeled "Use RSA ... key to log in", then use the private key button located next to this line to navigate to your private key file, and click Ok.

Batch clusters

Our SLURM clusters process jobs in batch and require the ability to SSH without entering a password. When creating a key for use with SLURM, follow the above instructions for creating keys without passwords.

After creating this key pair please make sure you follow the copy the public key instructions above to localhost. This will ensure that your key will be usable on all the cluster nodes since they have a shared home directory.

SSH Agents

While it is very useful to protect your SSH key pair with a pass-phrase it can very time consuming to re-type the pass-phrase over and over. SSH provides a agent that runs in the background and allow you add a key(s) to it with a time limit that they will be unlocked for.

ssh-agent bashssh-add -t $TIME

The time specified by -t is specified in seconds.

Example:(The following would start a bash shell with passwordless SSH active for 30 minutes.)

ssh-agent bashssh-add -t 1800

You will be prompted for your passphrase and, when entered correctly, you will be able to SSH without entering a password. You can check what keys are load when you are running inside a ssh-agent by using the command ssh-add -l.

Example:

bash-4.2$ ssh-add -l2048 ee:83:10:c8:2f:2c:17:5e:ef:80:42:7e:ff:75:9e:53 /home/username/.ssh/id_rsa (RSA)
SSH/Keys - UMIACS (2024)

FAQs

How to generate keys for SSH? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How do I see my SSH keys? ›

Checking for existing SSH keys
  1. Open Terminal .
  2. Enter ls -al ~/.ssh to see if existing SSH keys are present. $ ls -al ~/.ssh # Lists the files in your .ssh directory, if they exist.
  3. Check the directory listing to see if you already have a public SSH key. ...
  4. Either generate a new SSH key or upload an existing key.

How to SSH with a key? ›

The SSH public key authentication has four steps:
  1. Generate a private and public key, known as the key pair. ...
  2. Add the corresponding public key to the server.
  3. The server stores and marks the public key as approved.
  4. The server allows access to anyone who proves the ownership of the corresponding private key.
Aug 10, 2021

How to generate SSH key RSA 2048? ›

Generate an SSH Key Pair on Windows Using the PuTTYgen Program
  1. Run the PuTTYgen program. ...
  2. Set the Type of key to generate option to SSH-2 RSA.
  3. In the Number of bits in a generated key box, enter 2048.
  4. Click Generate to generate a public/private key pair.

How to get SSH key from terminal? ›

Creating SSH Keys (Terminal)
  1. Create an .ssh folder in the home directory. Create a .ssh folder in your user account's home directory if it doesn't already exist: $ mkdir /home/<user name>/.ssh. ...
  2. Use ssh-keygen to generate SSH key. ...
  3. Retrieve the public key file. ...
  4. Use the key in an async session.

How do I generate SSH keys for someone else? ›

You can generate the keys for another user the exact same way. You just write them into the appropriate place into the users home directory, ~/. ssh . Then set the permissions on the key files appropriately.

How to generate RSA key? ›

Generate RSA Keys
  1. Open a shell using Putty or another utility.
  2. Use commands to generate an RSA key file. Type the following command to generate RSA keys: ssh-keygen -t rsa. ...
  3. Navigate to the. rsakey. folder that you created in step 2b. ...
  4. Locate the public key beginning with. ssh. and copy the key.

How do I find my default SSH key? ›

The default directory for SSH keys is ~/. ssh with the private key named id_rsa and the public key named id_rsa. pub . By using the default file names, the SSH client will be able to automatically locate the keys during authentication so it is strongly recommended to not change them.

Can I have multiple SSH keys? ›

If you wish to gain regular access to the Git Fusion host, you can specify the correct key in your ssh command. Alternatively, you can manage multiple SSH keys using the SSH 'config' file on your local machine. This file is located at '~/. ssh/config' when using Linux, Mac or 'Git Bash' on Windows.

What is an example of a SSH key? ›

An example of an SSH key can be ssh-id-rsa This is an RSA key often stored in an SSH authorized_keys file. It is especially important for maintaining secure connections in Windows systems.

Where is the SSH key stored? ›

On Linux systems, the default location for SSH keys is in the user's personal directory in the file ~/. ssh/known_hosts. On Windows systems, the default file location is in the user's personal directory in the file C:\Users\username\. ssh\known_hosts.

Does SSH require a key? ›

An SSH key relies upon the use of two related but asymmetric keys, a public key and a private key, that together create a key pair that is used as the secure access credential.

How to get an SSH key? ›

Generate an SSH Key Pair
  1. Run the ssh-keygen command. You can use the -t option to specify the type of key to create. ...
  2. The command prompts you to enter the path to the file in which you want to save the key. ...
  3. The command prompts you to enter a passphrase. ...
  4. When prompted, enter the passphrase again to confirm it.

Is SSH key 1024 or 2048? ›

The regulations that govern the use case for SSH may require a specific key length to be used. In general, 2048 bits is considered to be sufficient for RSA keys.

What are SSH host keys? ›

Definitions: A public key used for authenticating a host in the SSH protocol to hosts that want to communicate with it (each host also generally has its own private host key). Some hosts may have more than one host key (e.g., one for each algorithm).

How do I find and copy a SSH key? ›

How to view your SSH public key on Linux
  1. Run the command: ssh-agent sh -c 'ssh-add; ssh-add -L'
  2. Upon successful authentication, your SSH public key will print out in the terminal.
  3. You can then copy that and paste it where you need it.
Jun 29, 2023

What is the SSH public key? ›

An SSH key is used to access a remote server through an SSH connection. The keys come in pairs, a public key and a private key. The public key is kept within the server and the private key is with the user or the client. The server authenticates the user by sending a message encrypted using the public key.

What is the command to enter SSH? ›

You can start an SSH session in your command prompt by executing ssh user@machine and you will be prompted to enter your password.

How to create SSH key via PuTTY? ›

To generate a new key, open PuTTYgen and click the Generate button. In the Key Generator window, check that the type of key to generate at the bottom is set to RSA. This will create an SSH-2 RSA key. The older SSH-1 was the standard's first version but is now considered obsolete.

How to create SSH deploy key? ›

Set up deploy keys
  1. Run the ssh-keygen procedure on your server, and remember where you save the generated public and private rsa key pair.
  2. On GitHub.com, navigate to the main page of the repository.
  3. Under your repository name, click Settings. ...
  4. In the sidebar, click Deploy Keys.
  5. Click Add deploy key.

How to generate two SSH keys? ›

Table of Contents
  1. Step 1: Double-check if you have an existing SSH key. ...
  2. Step 2a: If you don't have an existing SSH key, generate a new SSH key. ...
  3. Step 2b: Save the SSH key in the according file of your choice. ...
  4. Step 3: Adding the SSH to the ssh-agent. ...
  5. Step 4: Add your SSH private key to the ssh-agent.

How do I generate SSH keys for SFTP? ›

Users can generate their own SSH keys by logging in with their username and password, selecting their username at the top right of the page, selecting My account > SFTP keys > Add SFTP key, selecting the Generate in browser option, then selecting Generate key pair.

Top Articles
The 15/3 Credit Card Payment Hack: How, Why, and When It Works
Frames per second (FPS) in TV, cinema, and gaming
Average Jonas Wife
Lakers Game Summary
Rubratings Tampa
Genesis Parsippany
Amtrust Bank Cd Rates
Explore Tarot: Your Ultimate Tarot Cheat Sheet for Beginners
Carter Joseph Hopf
Prices Way Too High Crossword Clue
Matthew Rotuno Johnson
Turning the System On or Off
No Strings Attached 123Movies
Nebraska Furniture Tables
Labor Gigs On Craigslist
Mail.zsthost Change Password
Justified Official Series Trailer
Grandview Outlet Westwood Ky
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Saatva Memory Foam Hybrid mattress review 2024
The best firm mattress 2024, approved by sleep experts
Hewn New Bedford
Ford F-350 Models Trim Levels and Packages
Engineering Beauties Chapter 1
What Are The Symptoms Of A Bad Solenoid Pack E4od?
TeamNet | Agilio Software
1145 Barnett Drive
SOGo Groupware - Rechenzentrum Universität Osnabrück
Star Wars Armada Wikia
Pixel Combat Unblocked
Myra's Floral Princeton Wv
Sun-Tattler from Hollywood, Florida
Atlantic Broadband Email Login Pronto
Radical Red Doc
Nobodyhome.tv Reddit
159R Bus Schedule Pdf
Paperless Employee/Kiewit Pay Statements
2020 Can-Am DS 90 X Vs 2020 Honda TRX90X: By the Numbers
If You're Getting Your Nails Done, You Absolutely Need to Tip—Here's How Much
Memberweb Bw
30 Years Of Adonis Eng Sub
8 4 Study Guide And Intervention Trigonometry
Lesson 5 Homework 4.5 Answer Key
German American Bank Owenton Ky
A Snowy Day In Oakland Showtimes Near Maya Pittsburg Cinemas
Strange World Showtimes Near Atlas Cinemas Great Lakes Stadium 16
WHAT WE CAN DO | Arizona Tile
Jesus Calling Oct 6
How to Choose Where to Study Abroad
login.microsoftonline.com Reviews | scam or legit check
Dinargurus
Latest Posts
Article information

Author: Chrissy Homenick

Last Updated:

Views: 6074

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Chrissy Homenick

Birthday: 2001-10-22

Address: 611 Kuhn Oval, Feltonbury, NY 02783-3818

Phone: +96619177651654

Job: Mining Representative

Hobby: amateur radio, Sculling, Knife making, Gardening, Watching movies, Gunsmithing, Video gaming

Introduction: My name is Chrissy Homenick, I am a tender, funny, determined, tender, glorious, fancy, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.