4

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...

2 Answers2

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.

grawity
  • 501,077
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
  • 1,274