Generate SSH Key
How to generate SSH Key
The best place to generate SSH key is ~/.ssh/ directory. Please use the following command to generate it
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"The above command will generate a public key and private key with the name it gives you.
Add SSH Key to SSH Agent: Start the agent and add your key
eval $(ssh-agent -s)
ssh-add ~/.ssh/work
Add SSH Key to GitHub: Copy your public key:
cat ~/.ssh/id_rsa.pub
orcat ~/.ssh/work.pubGo to GitHub → Settings → SSH and GPG keys → New SSH key → Paste and save.
Test SSH Connection:
ssh -T git@github.com
You should see a welcome message.
To get the id of the private key that the ssh server uses to get the public key against it
ssh-keygen -lf <private-key>
###
### -l instructs ssh-keygen to show the fingerprint of the specified public or private key
### -f specified the path of the private or public key
###
Sequence Diagram
While adding a pem file to ssh-add remember to set the permission to the pem file to 600 owner can read or write else the Linux terminal gives
Permissions 0777 for 'awsprivatekey.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored.
SSH agent forwarding is a mechanism within the Secure Shell (SSH) protocol that allows a local SSH client to use the local ssh-agent on a remote server as if the agent were running locally on that server. This enables single sign-on across multiple SSH connections, even through intermediate "jump" or "bastion" hosts, without storing private keys on those intermedi ate systems.
To do it we can do
ssh -A ec2-user@public-ip-address-of-instance-in-public-subnet ssh ec2-user@private-ip-address-of-instance-in-private-subnet