How to scp as different user in perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to scp as different user in perl script
# 1  
Old 09-18-2008
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  
Old 09-18-2008
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  
Old 09-18-2008
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  
Old 09-18-2008
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  
Old 09-18-2008
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 "$ $"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Root running a script calling to scp using user "xyz" is not authenticating!

Close duplicate thread. (0 Replies)
Discussion started by: denissi
0 Replies

2. Shell Programming and Scripting

How to scp File from root user in one server to say crt user in another server and avoid password?

Can someone help in writing some script through which I can transfer file (scp) from root user in abc server to crt user in hfg server and can give the crt user password in script itself so that it doesn't prompt me every time for password (4 Replies)
Discussion started by: Moon1234
4 Replies

3. Shell Programming and Scripting

perl script to open an executable and pass the user credentials

Is it possible to open an executable file and pass user credentials through the perl script. If yes Please do share the CPAN module names and the way to access the executable file. For eg. I want to open the IBM LOTUS Sametime through my perl code and pass the user credentials like... (1 Reply)
Discussion started by: giridhar276
1 Replies

4. Programming

Perl script remote execution as another user

Hi gurus, I have a requirement where I need to remotely run a perl script as another user. Running the script locally as the required user is fine, however I need to su with the script due to filesystem permission issues. I do not want to update permissions on the remote server due to security... (5 Replies)
Discussion started by: melias
5 Replies

5. UNIX for Advanced & Expert Users

perl script to transfer newly generated files by scp

Hi all, I have root directory on server 1 say A and having sub directory B now my application generates output files and put in sub directory B. now i need to transfer these files from server1 to server2 by scp which is having same directory structure A and sub directory B I have tried... (2 Replies)
Discussion started by: tushar_spatil
2 Replies

6. Shell Programming and Scripting

How to get list of user into an array in perl script

Hi, cut -d: -f1,3 /etc/group >rpt.out I have a doubt in perl. right i am getting list of group user id into rpt.out file. instead i need to store it as an array in perl script. could you please tell me how can i get list of user into an array in perl script.. thanks in advance. (1 Reply)
Discussion started by: solo123
1 Replies

7. Shell Programming and Scripting

Executing program with Perl script but needs user input

Hello, I'm running a perl script to execute a program through my Unix command line. The program requires a user input but I want to automatically have perl input the string. Is there a way to do this? Thanks (1 Reply)
Discussion started by: leonard2352
1 Replies

8. Shell Programming and Scripting

Problem while scp if bashrc calls Perl script

A weird thing, happened today: When i do SCP from a remote server, file is not getting copied to here. Application Server: Here is where i work, and have a login. I have several tweaks in .bashrc, and along with all those, today i called a PERL script from bashrc. So when ever i do scp from a... (4 Replies)
Discussion started by: thegeek
4 Replies

9. Shell Programming and Scripting

allocate user quota using perl script

Hi I'm a student who is studying system administration. I need to write a perl script to allocate disk quota to users. I'm using ubuntu and When I try to run edquota command in command line it says that Can't find file system with quota. pls help me. I tried to edit fstab. but didn't work. ... (1 Reply)
Discussion started by: piumali
1 Replies

10. UNIX for Dummies Questions & Answers

scp with a sudo user

Morning guys, I'm hoping you can advise me as to whether or not the following is possible. Is there a way of firing off an scp command with a sudo user as the user? e.g. I am logged onto server1 as smith, but want to pull files from server2 that I can only read as sudo jones. In my mind it... (3 Replies)
Discussion started by: dlam
3 Replies
Login or Register to Ask a Question