Generate SSH Key pair & Add to Agent
SSH from one ec2 to another ec2. Generate key and SSH from one VM to another VM.
Step 1
Generate key in your client machine/laptop
or non-interactivelyStep 2: Linux & Mac
Add the key to your ssh-agent. Doing this will make life easier. You will not have to provide a private key during ssh in the terminal
Step 2: Windows
# By default the ssh-agent service is disabled. Allow it to be manually started for the next step to work.
# Make sure you're running as an Administrator.
Get-Service ssh-agent | Set-Service -StartupType Manual
# Start the service
Start-Service ssh-agent
# This should return a status of Running
Get-Service ssh-agent
# Now load your key files into ssh-agent
ssh-add ~\.ssh\id_rsa
Step 3
Now copy the contents of the file id_rsa.pub
to the clipboard.
Step 4
In the remote server in which you want to SSH/setup SSH. It might sound funny/confusing, but yes you need to access this system (i.e. login with SSH or user-password) and modify some files. Without this, you cannot proceed further.
Step 5
Now everything is ready
You can now ssh from your client to a remote machine with just one command. Replace username
with your remote machine username and replace your IP address.