Reputation: 16002
I want to copy a file from my one rails application to a remote/ another application hosted on an aws ec2 instance. I have my security group TCP ports 21 and 21 open for ssh and sftp. But I'm not able to figure out any way to do it. I've tried scp
so far and, it does not work.
I tried this:
scp -i ec2-keypair.pem myfile.txt ubuntu@my-public-ec2-ip:/home/ubuntu/my_new_file.txt
It prompts this: Using /home/ubuntu/.rvm/gems/ruby-1.8.7-p334
and exit. But file transfer doesn't happen. What could be the possible issue??
And also if, you know any better solution to do the same then, please help me with your knowledge. Thanks
EDIT : It would be great if, the solution is available in ruby
or ruby on rails
. Cause ultimately I have to transfer a file from one rails application to another.
EDIT : When I do scp -v -i ~/.ec2/ec2-keypair.pem Gemfile.lock [email protected]:/home/ubuntu/apps/
I get this: http://pastie.org/3613259
and see here: http://pastie.org/3613269 for more verbose output with -vvv
Upvotes: 0
Views: 581
Reputation: 14018
So I found this thread, and the last item might be relevant. http://centos.org/modules/newbb/viewtopic.php?topic_id=30515&forum=42
(btw, ssh -vvv will get you debug level 3, with even more inscrutable details).
So to be sure, the most common problem is that the permissions on the .ssh directory (on both local and remote hosts) somehow get overly permissive and ssh will refuse to use the credentials. Perms on the .ssh
directory should be rwx
for user only (octal chmod 700
), rw
for user on the private key and .pem keypairs, and group/all readable for other files.
drwx------ 11 tharrison staff 374 Mar 1 16:37 .
drwxr-xr-x+ 79 tharrison staff 2686 Mar 8 10:43 ..
-rw-r--r-- 1 tharrison staff 128 Aug 16 2010 .ssh-agent
-rw-r--r-- 1 tharrison staff 132 Dec 29 14:42 config
-rw------- 1 tharrison staff 1675 Apr 20 2009 id_rsa
-rw-r--r--@ 1 tharrison staff 405 Apr 20 2009 id_rsa.pub
-rw-r--r-- 1 tharrison staff 2805 Mar 5 08:33 known_hosts
-rw-------@ 1 tharrison staff 1693 Apr 27 2011 my-aws-keypair.pem
SSH is (properly) paranoid about what it will send to any log -- it doesn't want to give away any hints about what is or is not working as those hints could be used to discover vulnerabilities, etc. So the logs can be helpful ... occasionally.
But I am not sure any of this is right, because I think you said you're able to log in successfully from the command line using ssh, and that scp doesn't work -- this kind of rules out ssh authentication issues (as I said, scp is really just ssh), which is why it's worth making sure that the user you're logging in as remotely has proper permissions to write the file to the location you're sending it.
Maybe try ssh -i mykeypair.pem [email protected] 'touch ~/foo'
All values starting "my" need to be replaced with the correct values, e.g. mykeypair.pem
will need to have the path and name of the keypair you use to log in. If this works, it will create a file named foo in myuser's home directory on the server myremote.host -- log in using ssh without the command and check -- then you have proper permissions, at least to that directory. Now try to the real directory.
If it fails there, then check that all the directories in the path are group-x or all-x and the target directory is group or all rwx.
EDIT: corrected test ssh command and expanded on procedure and clarified.
Upvotes: 1