Jurgen, Thanks for asking. Initially, I wanted to say, "not possible," but then I considered the form of your question and realized that there was a way.
date | ssh localhost 'sudo sh -c "/bin/cat > /etc/tmp"' The core of this is that you can pipe into ssh and it'll connect it through the session. I'd seen this in examples for tarring files across an ssh session for file transfers; never really used it. The nasty bit is, as I have it, I had to add sh to the sudo file. Ok, nasty is an understatement, this is detestable; don't do it. For your solution, you'll probably want to write a little script that just does, "cat > $file", and add the script to /etc/sudoers. The input redirection isn't interpreted as part of the sudo command; it's still the local account, thus the small script or sh -c wrapper. If there's a better way around this, please share. I also had issue with typing the password for the sudo, so I just used nopasswd for the test. so, your file transfer should be something like (not tested): cat /path/to/source | ssh host "sudo dump.sh" dump.sh: #!/bin/sh cat > $1 -- Jess Males -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Jurgen Lamsens Sent: Friday, September 25, 2009 6:52 AM To: [email protected] Subject: remote scp command Hi, I hope I'm at the right place for my question. Consider this: jlams...@ubuntu1:~$ cat /etc/hosts 127.0.0.1 localhost 192.168.155.186 ubuntu1 192.168.155.187 ubuntu2 jlams...@ubuntu1:~$ touch file.txt 1.) This works, because I can write to /tmp jlams...@ubuntu1:~$ scp file.txt [email protected]:/tmp [email protected]'s password: file.txt 100% 0 0.0KB/s 00:00 2.) This works, because I use sudo jlams...@ubuntu1:~$ ssh [email protected] 'sudo touch /root/file.txt' [email protected]'s password: 3.) I want to scp to a directory that I do not have access to, but I cannot give some kind of sudo parameter to scp: jlams...@ubuntu1:~$ scp file.txt [email protected]:/root/ [email protected]'s password: scp: /root//file.txt: Permission denied How can I make the last one work in one shot, knowing that I can use sudo in step 2.) -> I don't want to login to ubuntu2, and do the scp the other way arount -> I don't want to scp to e.g. ubuntu2:/tmp first, login to ubunt2 and move from ubuntu2:/tmp to ubuntu2:/root Thanks in advance, Kind regards, Jurgen Lamsens
