0

I had a script which is used to create dumps of Database and transfers the files from Ubuntu server to Linux machine, I use scp for file transfer it prompts for password every time, need to automate it. I had the Rsa public key of Linux in Ubuntu machine as authorized_keys, when i scp it says Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password) checked the permissions and every thing like passwordAuthontication off etc no luck.

Can i write the password in my script and use regardless of security as i will provide 700 permissin and no one can access it except me the root user.

This is my script:

export DB_DUMP_DIR=/home/database_dump
export DB_NAME=database_name_$(date '+%Y_%m_%d').sql

mysqldump -u root  mysql > ${DB_DUMP_DIR}/${DB_NAME}
if [ $? -eq 0 ];then
 scp -i /root/.ssh/id_rsa  ${DB_DUMP_DIR}/${DB_NAME} root@192.0.0.0:
else
    echo "Error generating database dump"
fi
jas
  • 1
  • 1
  • 6

1 Answers1

0

The first things that come to mind are

  • Is the server set to allow key authentication authentication? (that's PubkeyAuthentication yes in sshd_config)
  • Is the server allowing RSA keys? (this might look like RSAAuthentication no in your sshd_config)
  • Is root's ~/.ssh directory set to 700? (or tighter)
  • Is root's ~/.ssh/authorized_keys set to 600? (or tighter)
  • Is the remote machine allowing you to log in as root? (the PermitRootLogin no option in sshd_config)
  • Is it really the right key you're sending here? Did you try with a different key you created just to test this?

Lastly, it is never, ever a good idea to write the password down in a script. Just don't do it. Fix the problem you have with key authentication here instead.

jane arc
  • 574
  • 3
  • 16