Thursday, May 21, 2009

Simulate SCP using SSH

An interesting question
How to simulate scp using ssh ...
Using the same way you sud be able to run a script in your machine on the remote machine.

I assume that the reader is aware of what SCP and SSH is.

Lets try this...


deepak@deepak-laptop:~$ cat abcd.txt | ssh deepak@jeeves ' cat > abcd.txt;chmod 0777 abcd.txt;./abcd.txt;'

deepak@jeeves's password:
abcd.txt
Desktop
Thu May 21 14:40:58 IST 2009
/home/deepak
jeeves

deepak@deepak-laptop:~$ cat abcd.txt
ls
date
pwd
hostname


deepak@deepak-laptop:~$




So how does this work...
The cat wud obviously get the contents of the file and pipe it to the STDIN of the remote system. At the remote system the cat would redirect the contents of STDIN into the file (thereby creating the file) and then changing its permissions and then executing it.
Simple enough but not easy to find at once.

Other recommended scripts would be

cat abcd.txt | ssh deepak@jeeves ' cat -|bash' # remote exec of command
cat abcd.txt | ssh deepak@jeeves ' cat > filename' # scp

Thanking you
Layman

No comments:

Post a Comment