How to respond to password prompt when using SCP in a shell script?

后端 未结 12 1209
旧巷少年郎
旧巷少年郎 2020-12-16 19:21

First of all, I am well aware of that there are many of questions regarding this topic. I have read them, but still could figure out an appropriate answer for my situation.<

12条回答
  •  难免孤独
    2020-12-16 19:51

    Once you set up ssh-keygen as explained here, you can do

    scp -i ~/.ssh/id_rsa /local/path/to/file remote@ip.com:/path/in/remote/server/

    where id_rsa is the local key generated in the ssh-keygen setup.

    If you want to lessen typing each time, you can modify your .bash_profile file and put

    alias remote_scp='scp -i ~/.ssh/id_rsa /local/path/to/file remote@ip.com:/path/in/remote/server/
    

    Then from your terminal do source ~/.bash_profile. Afterwards if you type remote_scp in your terminal it should run the scp command without password.

提交回复
热议问题