run python through openssh - python

I have made a connection between my openssh client and server. Both sides are window machine. I fail to do the followings:
Enter the python command line interface on my SSH client side, which can be done by entering "python" directly through a command line.
I want to run a python script on a server side by calling it on my client side. This script calls a commercial library to download data from a commercial database.
I can do both perfectly through remote desktop on the server side, but when I use openssh to connect, all fail. Any way to solve, especially item (2)?

If Python is installed on the remote server as C:\Python27 and the script is C:\Foo\bar.py, then get PuTTY. It contains the program plink.exe which can execute remote commands.
The command for you should be
plink.exe user#remote C:\Python27\python C:\Foo\bar.py
as explained in http://the.earth.li/~sgtatham/putty/0.64/htmldoc/Chapter7.html#plink-usage

Related

Create terminal for ssh on socket with Python

I need to create a terminal/console program on my server compute and I want to connect to it with ssh from client. And I want to do it from a python script. So, I figured that I need to somehow have this script run the program (subprocess maybe?) and put it out on the socket.
How can I put out a certain program on a specified socket for ssh connection?
Can I even ssh to a certain program run in a console, not to a whole PC? I need client to have only acces to what I set up.
How can I put out a certain program on a specified socket for ssh connection?
I think that what you actually want to do is changing what is run when logging in with ssh.
You can do this in /etc/passwd by changing /bin/bash to the program you want to run when you log in. Do this for the user that you want to log in to via ssh.
I didn't understand if you wanted to log in from a python script or log in to a python program in an interactive shell, so:
You can use the paramiko library to log into a machine with ssh. (if that is what you want)
I need to create a terminal/console program on my server compute and I want to connect to it with ssh from client.
You can look at this project https://github.com/python-cmd2/cmd2 to build interactive console programs in python.

How to connect to ssh server from another server

I've been trying to connect to first an out-of-band management server (in my case, since I'm connecting to DELL-servers, an iDRAC) and through that connect to the main server itself. I've got it to work when I do it manually, using, in the (windows) terminal:
putty.exe -ssh 'username'#'iDRAC-IP'
followed by PuTTY window opening where I type in the password, followed by
connect
which connects to the server itself, and then I type in the username and password for the server, completing the process.
When I've been writing my script in python, I'm using paramiko, http://www.paramiko.org/, suggested here on stackoverflow, and following this example: https://www.ivankrizsan.se/2016/04/24/execute-shell-commands-over-ssh-using-python-and-paramiko/, and it works just splendid for the iDRAC (the first server I connect to). It also works when I type in
stdin, stdout, stderr = ssh_client.exec_command('connect')
because I am still in my first server (ssh_client) (I can tell this is working because when I try to connect to the server manually afterwards, it is occupied). But after that it stops working, since when doing 'connect' I am no longer in ssh_client, but in a different server.
So my question is - how do I connect to a server from another server (in this case being the out-of-band management server) and log in to this one?
You can use ssh tunnel to do so.
this post may resolve your problem:
PyCharm: Configuring multi-hop remote Interpreters via SSH

Connect remote server to spyder for running Python Code

Here is what I am trying to do. I have a Windows VM and another Linux VM which is used as server. I have Spyder installed on my Windows VM and would like to run my Python code in Spyder on remote Linux server.
I did try using option in Spyder called "Connect to remote kernel" but it did not work and I am getting error "Could not open ssh tunnel ; Paramiko not available". I was using username#servername:22 for making ssh connection. Needless to say, I am able to ssh the machine using putty but not using Spyder. Any ideas how should I fix this?
I found another way to make a connection to an external server, here is the link explaining step by step.
Basically, you have to connect your client PC to the server through a PuTTY SSH tunnel, it will allow to redirect the client ports to the correct ipython kernel server ports.

Socket programming python on real server

I'm following this http://www.raywenderlich.com/3932 for socket programming in iOS where the server coding is in PYTHON, however, I just want to know that according to this tutorial, the author used localhost and run the code from terminal such that python server.py to execute and listen for socket.
What I'm confusing is that, how can I make this command on real server, such that after putting the code of python in CGI-BIN, how can I run that from shell/terminal of a shared web hosting.
Here's my SSH Screenshot, where I tried to run that command to bind and listen for socket, but Here i'm failed as no JAVA LOGIN section is appearing in my case as the video tutorial shows.
My Question is, How can I run the command so that the server will listen for the port, as on my localhost.
The command is: python server.py
On a shared web hosting server you probably have a running web server for which you write scripts which generate some output for the web server to return to the client.
server.py however is no such script. It contains the code for an actual server. Running the command starts the server. Therefore you won't get this working by simply putting the file in a CGI-BIN folder. You do need to run the command.

send argument to command prompt of a remote PC

I am looking for a way to open command prompt of remote PC by using Python. In this process I came only upto open a command prompt from Python and other code is connecting to a windows remote PC but how to combine these two and opening the command prompt of remote PC ?
Simply, I want to send some arguments/commands to remote PC command prompt.
Thank you.
First you need to install SSH on the remote PC's. You test the connection and make sure you are able to login. Google can help if you've not setup ssh before.
Then you can create a python script locally to execute commands over the ssh connection.
You'll probably want to look at either
Fabric -> http://docs.fabfile.org/en/1.8/
or
Paramiko -> http://www.paramiko.org/
Which will be able to run your commands.

Categories