Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Automate ssh command or scp (via a cron job)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
podollb
Apprentice
Apprentice


Joined: 05 May 2005
Posts: 190

PostPosted: Mon Jul 18, 2005 3:02 am    Post subject: Automate ssh command or scp (via a cron job) Reply with quote

If I want to connect to a remote system, and I need to use an ssh-agent to avoid manual user authentication how can I go about doing this in an automated way (in order to run cron jobs that could run a command via ssh or posisbly do a scp). I know I can manually start an ssh-agent but I was wondering if there was a way to start one automatically or anything like that. If that question doesn't make sense, then my question is how do people do such things in an automated way to avoid them to have to physically do something (like enter the password or start the agent).
Back to top
View user's profile Send private message
gentsquash
l33t
l33t


Joined: 03 Nov 2004
Posts: 753
Location: Still a Gentoo beginner.

PostPosted: Mon Jul 18, 2005 3:10 am    Post subject: Reply with quote

The ssh man-page will tell you how to make ssh keys (see
ssh-keygen). You can then install them on your remote system.
For my system, this allows me to remotely connect with no
request-for-password. I presume that you could do this in a
script run by a cron-job.

You referred to scp --you might want to consider rsync (as long as
your script is careful); rsync can copy symlinks, a talent that I find useful.
_________________
Your thread resolved? Putting [SOLVED] in its title helps all Gentooers. (Button "edit" , first post)
Prof. Jonathan LF King, Mathematics dept., University of Florida


Last edited by gentsquash on Mon Jul 18, 2005 10:26 am; edited 1 time in total
Back to top
View user's profile Send private message
trbecker
Tux's lil' helper
Tux's lil' helper


Joined: 19 Sep 2003
Posts: 136
Location: Novo Hamburgo, RS, Brazil

PostPosted: Mon Jul 18, 2005 3:13 am    Post subject: Reply with quote

You can use an identity file. Look at this: Key Management.
_________________
If you see any violations to the Guidelines, please report it.
Back to top
View user's profile Send private message
quag7
Apprentice
Apprentice


Joined: 12 Aug 2002
Posts: 288
Location: Marana, Arizona - USA

PostPosted: Mon Jul 18, 2005 6:31 am    Post subject: Reply with quote

This is from my notes file, hope it helps:

On client:

(1) ssh-keygen -t rsa

Accept default filename and default (blank) password
(Hit enter for password)

(2) Copy ~/.ssh/id_rsa.pub to your ~/.ssh directory on the server

ssh server.name.here "mkdir .ssh; chmod 0700 .ssh"
scp .ssh/id_rsa.pub server.name.here:.ssh/authorized_keys2

(OR, depending)

scp .ssh/id_rsa.pub server.name.here:.ssh/authorized_keys

I use this for a variety of purposes, and it works well. Since you are now using key-based authentication, there is no authentication prompt, and you can use scp or the ssh command in crons/shell scripts to execute commands on remote servers.
_________________
http://www.dataswamp.net
Back to top
View user's profile Send private message
podollb
Apprentice
Apprentice


Joined: 05 May 2005
Posts: 190

PostPosted: Mon Jul 18, 2005 2:35 pm    Post subject: Reply with quote

ok I guess maybe I must be doing something wrong, I already use a generated key and everything that people have suggested. My problem is that I always have to start an ssh-agent and enter my password before I can do any of my 'passwordless' stuff. I also have to make sure agent forwarding is enabled on all machines. This allows me to ssh between machines w/o prompting me for authentication. BUT my problem is that I don't know how to do it without starting an agent. Or is it as simple as just starting an ssh-agent once and then all my cron jobs (run as my username) will always use it?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum