LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 06-18-2008, 10:58 AM   #1
spellinator
LQ Newbie
 
Registered: Oct 2007
Posts: 13

Rep: Reputation: 0
Using scp in an Automated Way - How?


I'm using the scp command like this:

scp -p root@ip_address:/u/backups/bkup1* ./

...but it prompts for a password.

The man page shows a reference to an identity file that can be used with the -i option. How do I create an identify file?

Or is there a better way to create an automated copy between two servers?

I want to do this every night at 1 AM, so I want to setup something to cron. Any ideas are welcomed.


Thanks,
Danny
 
Old 06-18-2008, 11:04 AM   #2
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
you can set up a SSh key between the 2 servers.

http://www.linuxquestions.org/linux/...ation_with_ssh
 
Old 06-18-2008, 11:08 AM   #3
netdog
LQ Newbie
 
Registered: Dec 2007
Location: Richmond, VA
Distribution: Fedora, Slackware
Posts: 5

Rep: Reputation: 0
Generate keys...

Hey, the best bet for this is to set up a public/private key set for the deal. If you keep the private key on the originator and the public key on the target machine you can do the copy without a password (the keys will validate the login).

I would highly recommend the OReilly Linux Server Hacks book for the details. The section on SSH is well worth the time if you are moving files (or yourself) around between servers. In just a few pages it can totally change the way you run around inside you own machines.

Good Luck!
 
Old 06-18-2008, 11:20 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Edit the sshd_config file so that the server uses public key authentication rather than password authentication. Then add your public key to the authorized_keys file on the server. This is explained in the sshd_config man page and the comments of the sshd_config file. Consider adding a "from=" option to your entry in the authorized_keys file. The info for this is in the sshd man page.

If possible, try to log as a different user. For example, create a regular user for backup purposes (lets say buser) and save the backups in that users home directory instead of in /root.
The cron job can still be run as root on the local machine. Simply use a command like "scp -p buser@ip_address:/u/backups/bkup1* ./" instead.

The root account is a known entity. If you can disable root ssh logins you will be much safer.

Also, saving the files to /home/buser or another directory where buser has write access instead of /root. Remember that the ext3 and other filesystems reserve a percentage of drive space on the filesystem for the root user. That way if the drive is full (to normal users), the root user still has some wiggle room to work and remedy the problem. The /root directory is usually on the root (/) partition. If that fills up it could cause more problems than if the /home or /var/ partition filled up (asuming they are on their own partitions).
 
Old 06-18-2008, 03:49 PM   #5
spellinator
LQ Newbie
 
Registered: Oct 2007
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks for the Replies

Regarding the book, OReilly Linux Server Hacks:
Do you mean this one?
http://www.amazon.com/Linux-Server-H...3818449&sr=1-8
 
Old 06-18-2008, 04:31 PM   #6
spellinator
LQ Newbie
 
Registered: Oct 2007
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
Edit the sshd_config file so that the server uses public key authentication rather than password authentication.
Will this create a problem if I try to access when an SSH session from my Windows PC?

I mean, won't I need the public key installed on my Windows PC for it to work?


Thanks,
Danny
 
Old 06-18-2008, 06:58 PM   #7
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
If you use putty, there is a keygen.exe program that you can use to load in your private key (*.ppk). Load in your key and near the top of the window, the public key is displayed. You can highlight and copy this key, which is compatible with openssh's authorized_keys file. The putty keygen program even points this out.
 
Old 06-19-2008, 04:11 PM   #8
Lantzvillian
Member
 
Registered: Oct 2007
Location: BC, Canada
Distribution: Fedora, Debian
Posts: 210

Rep: Reputation: 41
You can use a keypair like mentioned above, or use Expect. Which automates prompts.
 
Old 06-20-2008, 11:07 AM   #9
netdog
LQ Newbie
 
Registered: Dec 2007
Location: Richmond, VA
Distribution: Fedora, Slackware
Posts: 5

Rep: Reputation: 0
yep, that's the book. $20 bucks and it has saved my butt more than once.
 
Old 06-26-2008, 05:09 PM   #10
spellinator
LQ Newbie
 
Registered: Oct 2007
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
If you use putty, there is a keygen.exe program that you can use to load in your private key (*.ppk). Load in your key and near the top of the window, the public key is displayed. You can highlight and copy this key, which is compatible with openssh's authorized_keys file. The putty keygen program even points this out.
Where do I get this keygen.exe? I tried to Google it, but I see a lot of hits that say it is a trojan.
 
Old 06-28-2008, 04:05 PM   #11
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Rep: Reputation: 31
spellinator,

you are looking for the wrong command. You should be looking for ssh-keygen to create a private/public key. You can easily create the key as follow:

1. ssh-keygen -t rsa
a. (select default unless you want to use passphase)
b. this will create 2 files in /home/userid/.ssh directory (id_rsa & id_rsa.pub)
c. cd /home/userid/.ssh
2. scp id_rsa.pub userid@server:.ssh/authorized_keys
3. repeat step 1 and 2 to all other servers

This will let you ssh and scp between server without password.

John
 
Old 09-04-2008, 12:41 AM   #12
mohdshakir
Member
 
Registered: Jan 2006
Distribution: gentoo, slackware
Posts: 36

Rep: Reputation: 15
cojo:

I guess it's not really a good idea to just replace the authorized_key file with the public key. I prefer to use ssh-copy-id instead.

Last edited by mohdshakir; 02-18-2009 at 05:41 PM.
 
  


Reply

Tags
automate, scp


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
scp does not work and gives the following error message: scp: FATAL: Executing ssh1 i akay Linux - Networking 16 09-29-2008 12:41 AM
Automated scp - needs paraphrase-less login? michaelsanford Linux - Networking 3 07-21-2005 01:14 AM
Automated mail ioanv Linux - Software 4 03-29-2005 03:47 AM
Automated SCP/SSH using Keychain gareth_western Linux - General 1 10-12-2004 10:43 AM
Automated HW/SW inventory. welby Linux - Software 2 07-10-2003 08:28 AM


All times are GMT -5. The time now is 12:03 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration