I have a passwordless ssh setup for ubuntu. It works fine, I can give ssh commands from the command line. But if I have a script that contains an ssh command, it still asks for my password. Example of command in script:
ssh ubuntu@localhost 'mkdir -p mydir'
Any ideas how to solve this problem?
Thanks, Serban
答案 0 :(得分:1)
I think what you mean is:
I can
ssh
to my server and run this script without a password as my own public key is in the server'sauthorized_keys
file, but when I run the script and itssh
's to itself, it asks for a password. Why?
If so, the answer is that the server does not your have your private key, so the entry in the authorized_keys
file is insufficient.
You can test this by seeing whether when logged into the server ssh ubuntu@localhost
asks for a password.
Either:
ssh-keygen
), and put the public element of that keypair into authorized_keys
.答案 1 :(得分:0)
In the server:
cd /home/ubuntu/.ssh/
cat id_rsa.pub >> authorized_keys
where id_rsa is your public key in the client from which you want to access the server.