ssh-keygen / passwordless login for sh/php script

I am trying to create a backup script that will send the backup to an external server. I need to be able to do this securely also.

I'm running into a problem with sending the password for scp, and I know there is a way to create a public/private key for the two servers, but from what I've read the keys need to be created without a password. I'm not sure what the security risks are for doing this. Offhand it sounds dangerous.
ShroderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fridomCEO/ProgrammerCommented:
Of course it is more unsecure, however you can restrict the login for the key to specific commands
see e.g
http://www.sun.com/bigadmin/features/articles/sec_shell_2.html
or here
http://www.oreilly.com/catalog/sshtdg/chapter/ch08.html

Regards
Friedrich
0
xDamoxCommented:
Hi,

I strongly recommend you read this on how to setup public and private keys

http://tutorials.linux-noob.com/tutorials/pkeyauth.pdf
0
pjedmondCommented:
Better still read this one....:

http://www.cvrti.utah.edu/~dustman/no-more-pw-ssh/

It shows you how to do the backups securely....and with a password to protect the keys (using agents). If you're going to do this, then you might as well do it properly.

HTH:)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ShroderAuthor Commented:
Thank you!
I'll take a peek. :)
0
ShroderAuthor Commented:
I'm not sure what I'm doing wrong. The keys generated fine. Moved them to the remote server. Set the permissions. Primed the agent. Attached the agent. But it still asks me for a password.
0
xDamoxCommented:
Who's guide did you follow? also did you edit the sshd_config file
0
MyrandorCommented:
Here's a small howto.

From the client, type this command to generate the certificate. Leave all the question by default.
> ssh-keygen -t dsa

Take the file named dsa.pub from the client and put the content in the file /root/.ssh/authorized_keys2 on the server using this synthax:
from="client_ip", ssh-dss ...
Ensure that the file is 600 to make sure that no one can read it. The line "from=..." will allow the connection only from the provided IP.

Now, from the client, do a "ssh root@server_ip" and accept the authentication. It should only ask once.

You can replace the "root" username by any username you want. Just make sure it has a shell access.

If you have a problem connecting, you can try to put the line "PermitRootLogin without-password" in your /etc/ssh/sshd_config. If it still doesn't work, look at the log in /var/log/messages or /var/log/secure and post the content. It could help find the exact reason.
0
ShroderAuthor Commented:
ok. I can try that shortly.

One thing I noticed is the from contains something like from= root@249-250-233-5.dedicated.isp.net should I change this to from= root@249.250.233.5?
0
MyrandorCommented:
Using the hostname or IP should not make any differences since the server will do a lookup for it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.