3

I tried using the scp command with the -i option to transfer the file from local machine to remote EC2 instance:

Akhis-Macbook-Pro:~ aswinakhilesh$ sudo scp -i Mykey.pem FileA ec2-user@ec2-23-20-46-45.compute-1.amazonaws.com:/home/FileA

Instead of the file being copied, I am getting the following message:

 Agent pid 2624

Akhis-Macbook-Pro:~ aswinakhilesh$ Identity added:
/home/.ssh/id_rsa (/home/id_rsa)

My .ssh folder in ec2 instance has the following files:

authorized_keys  
id_rsa  [Same as Mykey.pm, which is used with the -i option before]
known_hosts

It would be great if someone could help me out here!

Manolo
  • 360

4 Answers4

5

I just came across this same issue. The solution was what someone pointed out (if you have

eval `ssh-agent`

change it to

eval `ssh-agent' > /dev/null

BUT the important thing is that this needs to happen on the REMOTE host.

Martin
  • 181
3

What's in your .bashrc?

sshd will source .bashrc in your home directory when connecting with scp. It would appear that you have something like eval`ssh-agent` in that file.

If the .bashrc sends anything to STDOUT when sourced it will cause problems with scp (and likely other programs.) There are a few different ways to deal with it, easiest is to change to:

eval`ssh-agent` > /dev/null

You can also test if $PS1 is set to determine if it's an interactive shell, and then use conditional statements.

frameloss
  • 131
  • 3
1

For me it looks like your destination path is not right, at least a normal user should not have right to write directly into /home, however this should result in a permission denied for the scp command, still you can use

instead of:
ec2-user@ec2-23-20-46-45.compute-1.amazonaws.com:/home/FileA

the following:
ec2-user@ec2-23-20-46-45.compute-1.amazonaws.com:~/

p1100i
  • 1,010
0

The connection breaks if something is printed out while running scp. You probably have some underlying command(s) running through .bashrc (or similar) while logging in to the remote host. Even for non-interactive logins, like when you're using scp, it will keep sourcing login scripts in the target host.

Fix this by SSHing into the remote host and checking for commands that print something. You can then try commenting them (for a quick test) or redirecting their outputs to /dev/null to avoid this happening next time.