LinuxQuestions.org
Help answer threads with 0 replies.
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 11-11-2008, 12:37 AM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,462
Blog Entries: 6

Rep: Reputation: 51
SCP command script with password in same line??


I have written a script which will send the backup "adon.gz" file every evening at 6 from Node1 to Node2.
What I did is putting :
Code:
scp adon.gz root@10.14.234.321:/root
But I donno how to answer for password if it ask within script.

Is there any method to response for the password therein if the script ask for?Pls Help
 
Old 11-11-2008, 01:10 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Rather than the password, which is in the clear, the *usual* way of doing an scp without typing in a password is by setting up entries in the users' 'authorized_keys' files.

Assuming you have UserA and UserB who are on different machines, each of these users will have private and public key information in $HOME/.ssh/ - typically the user's info is 'id_rsa.pub' and 'id_rsa'. public key information from the remote user(s) would be in the file 'authorized_keys'. If those files do not exist, then they simply haven't been created yet.

I am assuming here that the sysadmin has put fairly lax restrictions on the use of ssh and that a user can connect to an arbitrary remote using their own key files *and* can even specify their own list of 'known_hosts'.

1. Creating the id_rsa key files: UserA and UserB each need to generate their respective key files:
ssh-keygen -b 2048 -t rsa -N "" -C "User A's Secret Recipe"

The '-N ""' means "no passphrase" - if you put on a passphrase that means you need to enter a passphrase to connect - which you don't want.

The "-C" is a comment - you can leave it blank or put in something to remind you what that key is for.

2. Setting up the known_hosts file:

ComputerA (which hosts UserA) will have a host key in /etc/ssh/ssh_host_rsa_key.pub you must add that file's contents to the $HOME/.ssh/known_hosts file on ComputerB. Or if admin restrictions prevent it, the admin must add the contents of that file to /etc/ssh/ssh_known_hosts.

Same for ComputerB - it needs its public host key info in the remote's known_hosts or ssh_known_hosts file.

3. Setting up the authorized_keys file:

UserA has a public key file .ssh/id_rsa.pub - the contents of that file must be added to UserB's .ssh/authorized_keys file.

At this point UserA can use scp/ssh/sftp (and other tools like rsync) to issue commands to ComputerB via UserB's account.

UserB also has a public key file - putting that information into UserA's authorized_keys file will now allow UserB to do horrible things to ComputerA using UserA's credentials.
 
  


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
Expect script, scp and find command unihiekka Programming 1 10-17-2008 03:11 PM
how to give password in shell script after scp kushkothari Linux - Networking 2 10-14-2008 12:13 AM
scp, how to pass password in script ebel.velda Linux - Software 4 07-17-2007 05:13 PM
automating scp copy, how to enter password via script? stefaandk Programming 3 11-29-2006 09:57 AM
Include scp password in command cli_man Linux - General 1 08-05-2005 03:47 PM


All times are GMT -5. The time now is 08:19 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