Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
scp -i ~/.ssh/id_rsa.pub events*$date*_QA.log $remote_user@$remote_server:$remote_location

Is the aforementioned script incorrect? Am I not doing it correctly?

I went to the .ssh directory and saw that the remote server is in the known_hosts file.

But, when I do ordinary scp without any file as parameter, it is still asking for password

scp events*$date*_QA.log $remote_user@$remote_server:$remote_location

How can I include the key file in my command?

sh-3.2$ grep server ~/.ssh/*
/home/user/.ssh/known_hosts:server....com,ip_addr ssh-rsa Asine=jhjsdhfjsadhfjkashdfjhasdjfhksadjfhasjdfhj
share|improve this question
 -i identity_file
         Selects the file from which the identity (private key) for public
         key authentication is read.  This option is directly passed to
         ssh(1).

Use ~/.ssh/id_rsa.

share|improve this answer
    
still asking for password sh-3.2$ scp -i ~/.ssh/id_rsa test_QA.log user@server:location user@server's password: – user122530 Mar 12 '12 at 21:23
    
@tech_learner strange, as that works for me – whitequark Mar 12 '12 at 22:04
1  
You may have to use an actual path, as in /home/user/ instead of ~. That seemed to have made it work for me. – Evan Darwin Feb 17 '13 at 21:15
1  
You want the local user's ~/.ssh/id_rsa.pub content placed in the remote server's authorized_keys file. It's usually in ~/.ssh/authorized_keys. You also need to be very particular about the file permissions on files in ~/.ssh, making them minimally accessible. sshd is very particular about the file permissions. – JR Lawhorne Apr 7 at 17:55

If it still asking for password, you should use the following command

scp -i /home/username/.ssh/id_rsa remote_server:file.ext /home/username/

Notice, remote_server, not username@remote_server.

share|improve this answer
1  
When not using username@ it uses your current username (which then should also exist on the remote server). So I don't understand how this would fix something (assuming you were replacing username with the actual username, like alex@, not username@). – Arjan Oct 7 '15 at 8:27
    
I try it now, you are really right, I'm not – Alex Ryasn Oct 8 '15 at 9:22
    
No worries, there's a "delete" link underneath your answer ;-) Thanks for trying to help! – Arjan Oct 8 '15 at 10:47

Tested and corrected via these instructions: http://askubuntu.com/questions/46930/how-can-i-set-up-password-less-ssh-login

The instructions here worked flawlessly when I tested on my boxes (CentOS/CentOS). I imagine the issue is your ssh keys are not tied to a username.

Example: cat authorized_keys # on Box I'm sshing/scpin' to ssh-rsa BLAHBLAHBLAHBLAH/zAcS4kD9pyPAjD3/gd5D1rcQa6IztCMR9yMXiGFnxviWsT8/oYevZw25k4yREuA8ibLKC9peH1X4LK1E+n7gq4TETexWkZbQ2XGLOX44eglra3MB4FShPg0cZXGcJWltPQ/y0Ay2A/KmaC14YrDfqwm7+ibTiUp4hOO8I6eIPmwwGn/2hs0SewJXisGqUx2v my_user@machine.local #username is tied to the key and is an authorized host

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.