SSH

RELATED: SETUP > Dev Environments > Git # Create SSH Key | SETUP > Cloud AWS > EC2 # SSH Key-pairs |

Setup

SSH Key-pairs

A key pair, consisting of a public key and a private key, is a set of security credentials that you use to prove your identity when connecting to an Amazon EC2 instance. Amazon EC2 stores the public key on your instance, and you store the private key. The public key is saved within the ~/.ssh/authorized_keys file. For Linux instances, the private key allows you to securely SSH into your instance. Anyone who possesses your private key can connect to your instances, so it's important that you store your private key in a secure place.

As an alternative to key pairs, you can use AWS Systems Manager Session Manager to connect to your instance with an interactive one-click browser-based shell or the AWS Command Line Interface (AWS CLI).

Source: AWS - Amazon EC2 key pairs and Linux instances

Configure SSH certificates for SSH authentication

Source: https://www.socketxp.com/iot/how-to-configure-and-setup-ssh-certificates-for-ssh-authentication/

SSH into a host

From terminal

  • ssh into a host using a certificate

$ ssh -i "/home/<user>/MyKeyPair.pem" <user-name>@<ip-address>
  • [Alternative] ssh forward when needing to hop to another ssh host from the first host; NOTE: make sure the ssh-agent is running, see below for how to setup ssh-agent

$ ssh -A <user-name>@<ip-address>
  • [Alternative] use AWS Systems Manager Session Manager to connect to your instance with an interactive one-click browser-based shell or the AWS Command Line Interface (AWS CLI).

Using putty

Setup and work with ssh-agent

  • check if ssh-agent is running

# ssh agent is not running
$ ps x | grep ssh-agent
  588 pts/1    S+     0:00 grep --color=auto ssh-agent

# ssh agent is running
$ ps x | grep ssh-agent
 2410 ?        Ss     0:00 ssh-agent -s
 3237 pts/0    S+     0:00 grep --color=auto ssh-agent
  • If not running, start ssh-agent and add the keypair. NOTE: when using with aws vpc setup, there may be some delay

$ eval "$(ssh-agent -s)"
Agent pid 2410

$ ssh-add /home/<user>/MyKeyPair.pem
Identity added: /home/<user>/MyKeyPair.pem (/home/<user>/MyKeyPair.pem)

Last updated