-1

When running python code using ssh on remote computer by a sudo user, does it save the code in the remote computer ? does the root user can see actual python code?

ssh user@remotehost < python /home/codes/script.py
Sara
  • 1
  • 2

1 Answers1

0

As you've written that, you're not running code on the remote computer. If you want to run the script locally you'd do:

python script.py

If you want to pipe the output of that script to a remote machine you'd do:

python script.py | ssh user@remotehost

If you want to run the script on the remote machine (though note that the script must already be on the remote machine):

ssh user@remotehost "python script.py"

If you want to run the local script on the remote machine, copy it there first:

scp script.py user@remotehost:
ssh user@remotehost "python script.py"

You can avoid the copy by piping it to a shell on the remote:

cat script.py | ssh user@remotehost 'python -'

The trailing - tells python to read the script from standard input.

I'm not quite sure what will happen in your example as it is actually attempting to pipe the contents of the python binary itself, and the script, to the remote host, which is unlikely to be something you actually want to do.

Synchro
  • 3,148
  • 6
  • 27
  • 38
  • It doesn't have a full path for the binary, so it would *not* pipe the binary in all likelihood. – vidarlo May 06 '23 at 14:47
  • @vidarlo I have edited the question, the python script was used with full path (of the local machine). So, does it copy into the remote machine ? – Sara May 06 '23 at 14:51
  • Doesn't change anything; your command makes *NO* sense. – vidarlo May 06 '23 at 14:57
  • @vidarlo Got it, both were same, so have put only one. – Sara May 06 '23 at 14:59
  • @vidarlo my command though no sense actually ran the program and got some outputs. How can I locate the directory on the remote machine where the script was saved (if in a likelihood) – Sara May 06 '23 at 15:38
  • @Synchro Would it be possible to find the file which might have saved in the remote machine – Sara May 06 '23 at 15:41
  • What makes you believe that anything was saved? – vidarlo May 06 '23 at 15:55
  • @vidarlo `I'm not quite sure what will happen in your example as it is actually attempting to pipe the contents of the python binary itself, and the script, to the remote host,...` – Sara May 06 '23 at 15:57
  • If you just used `user@remotehost` for the ssh connection, it would end up in that user’s home directory, somewhere like `/home/user`. – Synchro May 07 '23 at 18:29