Saturday, January 22, 2011

sftp for password-less authentication

As an org-wide move, ftp access is removed to all our unix systems.  With this change we had to change one of our scheduled jobs, which does the backup of our twiki application data.  This job runs with a common user id and I started to setup ssh based authentication as I already use this with putty.
  • create the key pair using "ssh-keygen -b1024 -t rsa"
  • didn't give password to the private key file as access has to be through script
  • so by default it created the files id_rsa & id_rsa.pub within .ssh folder in my home
  • copied the id_rsa.pub as authorized_keys2 under .ssh of the target machine
  • executed sftp -b /dev/fd/0 <user>@<target host>, still prompting for password
After searching through many forums, realized that the .ssh folder & authorized_keys2 file permissions need to be set properly.

chmod 700 .ssh
chmod 600 authorized_keys2

Still it wouldn't work.  Also observed that the .ssh folder was getting SGID bit set by default.

chmod -s .ssh

Still no luck.  Finally realized that the problem is because of the home (/u/test) folder itself.  It has 755 permissions as usual and only I changed it to 700, did sftp work with prompting for password.

No comments:

Post a Comment