scp -i ~/.ssh/id_rsa.pub events*$date*_QA.log $remote_user@$remote_server:$remote_locationIs 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_locationHow 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 4 Answers
-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.
This might help another noob.
[I know this is a redundant circular example but its good to illustrate] Scenario:
- ssh from Mac -> Ubuntu
- scp files from Mac -> Ubuntu
- close ssh and scp files from Ubuntu -> Mac
I had only created ssh keys on my Mac (via ssh-keygen) and shared them with the machine running Ubuntu via (ssh-copy-id). So I could copy files, while logged into my Mac from the machine running Ubuntu, but not the other way around.
Solution: I had to create ssh keys on the Ubuntu Machine and share them with my Mac. then I could successfully run the following command on the Ubuntu Machine
Mac IP: 192.168.1.40
Ubuntu IP: 192.168.1.38On Mac
ssh-keygen
ssh-copy-id ubuntu@192.168.1.38
ssh ubuntu@192.168.1.38
# Now on Ubuntu
ssh-keygen
ssh-copy-id MAC@192.168.1.40And now the following command should copy the file without asking for password to MAC
sudo scp -i /home/ubuntu/.ssh/id_rsa MAC@192.168.1.40:~/Documents/Fluff/Version-Control/tools/pull.sh . Tested and corrected via these instructions:
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 #username is tied to the key and is an authorized host
I usually use this:
scp -P <port_if_not_22> -i <path_to_keyfile> <source> <target>example:
scp -P 666 -i "T:\.ssh\id_rsa" "D:\somePath\someFile.txt" root@78.24.82.66:/root/Downloads/someFile.txt