LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-26-2015, 09:30 PM   #1
willc86
Member
 
Registered: Dec 2014
Posts: 54

Rep: Reputation: Disabled
rsync cronjob question


hey guys, sorry for asking a dumb question, but some of the terminology online is not grasping me well, and still leaving me confused


in crontab -e

I have a shell script that contains

rsync /home/willc86 willc86@server02:/home/willc86/backup

the script works good by itself, however i have to put in a password which I understand. i know crontab works, because i used rsync script in the local machine. I am just having problems trying to sync it to another server

how do i get this rsync going in crontab to back it up to another server.
 
Old 03-27-2015, 03:05 AM   #2
ttk
Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware
Posts: 461
Blog Entries: 17

Rep: Reputation: 463Reputation: 463Reputation: 463Reputation: 463Reputation: 463
A question, and something to try:

* The password you have to type, is it the password for the key, or the password for the destination server?

* If you copy the contents of the sending account's ~/.ssh/id_rsa.pub to the receiving account's ~/.ssh/authorized_keys does it start working? If not, the answer to the above question becomes quite important.
 
Old 03-27-2015, 10:12 AM   #3
willc86
Member
 
Registered: Dec 2014
Posts: 54

Original Poster
Rep: Reputation: Disabled
the password i type in is what i use to log on locally to the server.
example:
username: user1
pass: pass

that will log me in


i am sorry but i dont understand the 2nd part =/
so should i try copying the /id_rsa.pub
to the authorized_keys?

should i generate keys? would it still ask for a password?




i actually checked to see if i have a .ssh/id_rsa.pub file and i dont =/
do i have to generate one?

Last edited by willc86; 03-27-2015 at 11:24 AM.
 
Old 03-27-2015, 12:41 PM   #4
ttk
Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware
Posts: 461
Blog Entries: 17

Rep: Reputation: 463Reputation: 463Reputation: 463Reputation: 463Reputation: 463
Quote:
Originally Posted by willc86 View Post
the password i type in is what i use to log on locally to the server.
Good .. I was just making sure you didn't have keys already generated which had their own password.

Quote:
so should i try copying the /id_rsa.pub to the authorized_keys?

should i generate keys? would it still ask for a password?

i actually checked to see if i have a .ssh/id_rsa.pub file and i dont =/
do i have to generate one?
Yes, run "ssh-keygen" on the sending server (the one running the cron job) and just press Enter when it prompts you for a filepath and for a passphrase. Adding a passphrase to a key is an additional layer of security, but it gets in the way when you're automating tasks like this.

After ssh-keygen has run, there will be a /home/willc86/.ssh/id_rsa.pub file on that server. This is the public key part of the private/public keypair.

It is safe to pass the public key around as long as you keep the private key to yourself (the id_rsa file, without the .pub).

On server02, create a directory /home/willc86/.ssh, and copy the public key id_rsa.pub from the sending server to server02:/home/willc86/.ssh/authorized_keys -- this tells server02 that ssh connections using the private key matched to this public key are to be trusted, and to not require a password.

One last thing is needed: ssh or scp from the sending server to server02, so that the sending server gets an entry in .ssh/known_hosts. Afterwards, you should be able to ssh or scp from the first server to server02 without any prompts or entering a password.

There's a chance your sshd on server02 is configured to disallow this kind of authentication, but it's unlikely. If the instructions here don't work, show the commands you used and their responses, and the contents of /etc/ssh/sshd_config here and we'll sort it out.
 
Old 03-27-2015, 03:33 PM   #5
willc86
Member
 
Registered: Dec 2014
Posts: 54

Original Poster
Rep: Reputation: Disabled
thank you so much! it works =)

did exactly that created a key and sent it over to authorized_keys

i do have a question. How does linux know to look in .ssh/authorized_keys if i just did that directory myself. What if I were to rename authorized_keys to something else?
 
Old 03-27-2015, 04:04 PM   #6
ttk
Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware
Posts: 461
Blog Entries: 17

Rep: Reputation: 463Reputation: 463Reputation: 463Reputation: 463Reputation: 463
rsync defaults to using ssh for its data transport, which means it opens an ssh connection to the remote machine, where an sshd process is listening on TCP port 22.

When the sshd program accepts a connection, it is programmed to look in some standard locations for configuration and authentication data.

One of those locations (which can be overridden via configuration) is the user's .ssh directory. If that .ssh directory exists, it will look for files in it, like "config" and "authorized_keys" and "known_hosts".

It doesn't matter if the directory and the files in it were created by you, or someone else, or a script, or the "ssh-keygen" program, or created for you when the willc86 user account was created. If they exist, and contain information of a format sshd understands, sshd will use them. It's a program, and it was written to behave thus.

If you rename "authorized_keys" to some other name, sshd will not recognize it unless it is reconfigured to look for the file by its new name.

For a description of sshd's configuration/authentication-seeking behavior, see: http://www.manpagez.com/man/8/sshd/ and http://www.manpagez.com/man/5/sshd_config/ :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
question regarding a cronjob? Ajit Gunge Linux - Newbie 5 05-08-2012 12:54 AM
question regarding a cronjob? Ajit Gunge Linux - Software 3 05-03-2012 04:17 AM
cronjob rsync doesn't work vielmaj Linux - Server 6 03-28-2011 01:41 PM
Cronjob / script question nazs Linux - General 1 12-21-2006 02:45 PM
Cronjob question jungsonn Linux - Newbie 3 03-22-2003 10:04 PM


All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration