Problem scenario
You have a Linux server in AWS and another Linux server in Azure. You want to use scp without a password to transfer files rapidly. How do you configure passwordless SSH authentication between the two servers?
Solution
1. Run this command on each server:
ssh-keygen -t rsa -P ""
# Accept the default prompt by pressing enter.
2.i. Run this command on the AWS instance (replace "ubuntu" with "ec2-user" if the AWS instance is a RHEL server):
cat /home/ubuntu/.ssh/id_rsa.pub
2.ii. Append the output (of the above command) to this file where "george" is a username on the Azure server:
/home/george/.ssh/authorized_keys
# Create the authorized_keys file if it does not yet exist. RedHat servers do not necessarily have an authorized_keys file after ssh-keygen is run. If you have to create it run this command (from the .ssh directory): sudo chmod 600 authorized_keys
3.i. Run this command on the Azure instance where "george" is a username on the Azure server:
cat /home/george/.ssh/id_rsa.pub
3.ii. Append the output (of the above command) to this file on the AWS server (replace "ubuntu" with "ec2-user" if the AWS instance is a RHEL server):
/home/ubuntu/.ssh/authorized_keys
# Create the authorized_keys file if it does not yet exist.
4. Ensure that port 22 is not blocked via an Azure Network Security Group from the external IP address of the AWS EC-2 instance. To find the external IP address, use the AWS Console and go to the EC2 Dashboard. Alternatively from the backend you can run "curl http://icanhazip.com". Do not be alarmed in nmap commands show port 22 is blocked. Do not be alarmed if you cannot ping the Azure VM from the AWS instance.
5. Ensure that inbound ports 22 and 80 are not blocked in an AWS Security Group from the external IP address of the Azure VM. To find the external IP address, use the Azure Portal and go to resources and click on the VM. Alternatively from the backend you can run "curl http://icanhazip.com".
(Technically port 80 does not need to be opened. For nmap results to work from the Azure VM, port 80 needs to be opened. It is merely one port with one IP address. You can keep it blocked if you do not need to use the nmap command for troubleshooting.)
6. From the Azure instance, use this command:
ssh ubuntu@<IP address of server>
# replace "ubuntu" with "ec2-user" if the AWS instance is running Azure
# If you are prompted to continue connecting, choose "yes."
7. From the AWS instance, use this command:
ssh george@<IP address of Azure instance>
# replace "george" with the username on the Azure instance
# If you are prompted to continue connecting, choose "yes."
# We hope you found these directions succinct yet thorough, and very clear.