The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Calling a perl script from a perl script new2ss Shell Programming and Scripting 6 05-24-2009 06:03 PM
Running script from other user rather than login user rawatds Shell Programming and Scripting 3 01-30-2009 01:18 PM
How do i change to super user then revert back to ordinary user ,using shell script? wrapster Shell Programming and Scripting 3 06-04-2008 08:11 AM
How to set restricted user by rksh? Cannot use Perl module DBD::Oracle alanlh SUN Solaris 2 06-22-2007 01:10 PM
Perl: Run perl script in the current process vino Shell Programming and Scripting 10 12-09-2005 10:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-18-2008
sdubey sdubey is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
How to scp as different user in perl script

Hi,

I am writing a perl script that needs to change to a another user and scp files to a remote server. The passwords should not be prompted but read from a config file.

Please help.

Thanks

Sandeep
  #2 (permalink)  
Old 09-18-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
How do you plan on encrypting the config file to prevent it from being read?
It seems to me that the wisest course of action might be:

First, create ssh keys to allow your host to ssh into the remote host

Code:
scp /source/dir/file user@hostname:</target/dir>
scp -r /source/dir user@hostname:<target/dir>

  #3 (permalink)  
Old 09-18-2008
sdubey sdubey is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
Thanks. The config file storing the password will have proper permission set to avoid any other user reading it.

My main problem is, I need to scp as another user. How do I switch user and pass the password in the program. It is always prompting me for the password.

Thanks
  #4 (permalink)  
Old 09-18-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
You may consider changing the UID of the person running the perl script. setuid or some such...

Visit CPAN's site and take a look at Net::SCP Net::SCP - Perl extension for secure copy protocol - search.cpan.org.

It's the right way to do this...
  #5 (permalink)  
Old 09-18-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
Also, I did a quick google search for "Sending Password with scp", and ran across this site: sshpasswords[modp.com]
Here's what it had to say:
Quote:
#!/usr/bin/env expect -f # -*-tcl-*-
set timeout -1 # wait until done

# trick to pass in command-line args to spawn
eval spawn scp $argv

expect "password: $"
send "password\n"

# wait for regular shell prompt before quitting
# probably a better way using 'wait'
expect "$ $"
Closed Thread

Bookmarks

Tags
perl scp change user

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0