How to perform SCP as a Sudo user

4

2

Possible Duplicate:
scp to remote server with sudo

What is the best way of doing SCP from one box to the other as a sudo user. There are two servers

Server A

10.152.2.10

/home/oracle/export/files.txt

User : deploy

Server B

10.152.2.11

/home/oracle/import/

User : deploy
Sudo user : /usr/local/bin/tester

all i want is to copy files from server A to Server B as a sudo user...

In order to do this, first i normally login as deploy user on the target server and then switch as a sudo user without password.

after that SCP to copy file, this is the normal way i perform this activity...

In order to auotmate i have written script

#!/bin/sh
ssh deploy@lnx120 
sudo /usr/local/bin/tester "./tester/deploy.sh"

I have generated the private key for deploy user, so it allows me to login as deploy user without password. afterthar the sudo command is executed it will switch the user to tester...

after that nothing happens.. i mean the script is not getting executed ... is there any way to accomplish this in a different way...

Ramesh.T

Posted 2009-12-24T04:41:02.590

Reputation:

Question was closed 2010-05-08T00:50:17.937

1Please clarify/simplify what you are trying to do. I am finding the use of the term "sudo user" to be ambiguous. It seems that you are trying to automate an scp transfer, but what are the other limiting factors? – pcapademic – 2009-12-25T22:21:36.220

Answers

10

You can make a wrapper around ssh, like this:

#!/usr/bin/perl
use strict;
my $added = 0;
$added ||= s/^scp /sudo $&/ for @ARGV;
exec "ssh", @ARGV;

Make it executable, and run scp like this:

scp -S ./ssh-wrapper somefile anotherfile hostname.domain.tld:path/

This will only work if sudo on the remote server doesn't require a password (or if it's cached), but better than nothing.

user1686

Posted 2009-12-24T04:41:02.590

Reputation: 283 655

0

If I understand correctly, you need sudo because the file is somewhere your regular user does not have access to? And you do not have the root password, or do not want to use it for some reason?

One solution would be to copy the file to a location where you regular user has access to (and if necessary change the access rights on the file as well), and then perform the scp.

zpon

Posted 2009-12-24T04:41:02.590

Reputation: 832

3SSH is likely disabled for root. – Jeremy L – 2009-12-25T15:50:54.433