Nowadays, many websites are being hosted on cloud (Amazon Web Services) instead of traditional dedicated/shared Linux servers. Programmers who are using "scp" command to copy data from one Linux server to other Linux server are now facing issues to use same "scp" command for two ec2 instances/servers of AWS. The main reason behind this is, while using "scp" command, it asks for password of the server where the data is being copied and with ec2 instances of AWS, we normally have .ppk files and not a password.
Here is a solution for all the guys facing similar issue. If you implement this solution you can use scp command on ec2 instances without a password.
Steps to be followed:
- Steps to perform on first EC2 Instance (call server 1)
- Generate the keypair on server 1 on which you plan to run scp, ssh, sftp or rsync
- Login to server through shell and run the following command from anywhere
ssh-keygen -t rsa
- It usually shows location where files will be generated
- Do not enter any passphrase
- Steps to perform on second EC2 Instance (call server 2)
- Check the "sshd_config" on that server
- Typically it’s present in
- Please uncomment following two lines in sshd_config
Note => If you are logged in as EC2 User. Please do
sudo subecause only then it will allow editing of file
- Now find authorized_keys file of server2
- Location of authorized_keys file of server 2 as
- Next step is to append contents of id_rsa.pub file of server 1 to authorized_keys file of server 2
- Location of id_rsa.pub file of server 1 as
- Once you copy the contents of id_rsa.pub file of server1 to authorized_keys file of server2, YOU ARE DONE !
You will have to follow same steps if you want to run ssh, rsync or sftp commands.
Now command to fire on server 1
scp test1.txt email@example.com:/home/ec2-user/
firstname.lastname@example.org is Private DNS of server 2
You will get Private DNS of ec2 instance at AWS console