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