I'm using this tool to set up a ssh server on Windows. I'm trying to open the standard Python shell through a remote ssh connection but I simply can't get it to work. If I type 'python' in my ssh command line nothing happens, it just seems to wait for more input. My server machine however, shows a new python process running after I do this.
Running scripts works fine, though.
Do I need to use another Python shell, some other ssh server, some different configs?
Thanks
My guess is that Python is not recognising the stdin on the SSH shell as a terminal. I don't know why that would be.
However, try running "python -i" to overcome it.
The problem is probably that you're running the Windows Python executable, which expects a Windows console environment to run in, over a channel which doesn't support the features of Windows console. You might find Andy Koppe's conin to be useful.
Related
Using fabric 2.4 and trying to set up ssh keys to remotely connect to various linux servers?
Python is new to me, I've followed example on this site and Read python doc but still unclear to me.
Currently running python on windows and my script is able to connect to remote linux servers because i have connection string defined as follows:
ssh_connect = Connection(host='servername', user='user1', connect_kwargs={'password': 'blahblah'})
I am running python script from my window server and instead of defining the connection string, I would like it to use ssh key. I have the id_rsa.pub file from the linux server. I would like to setup up on my windows box and have the script use that for connections?
You can always just pass a key via Fabric through it's command line arguments. This is definitely kind of a vague question, especially since it's running fabric on Windows, which to my knowledge is not technically supported by them, though it does work.
fab -i /Path/to/key
Source: fab --help and the official documentation here
I'm running a script that's determining login information for me, and in the end is outputting the login information that I need to use.
I am running the script in a terminal, and now I want it to SSH me with the credentials it has, exit the Python script on my computer and connect my current terminal to the new server.
Say I already have my sshHost, sshUser and sshPass as variables in the script. How do I run an SSH command in the current terminal and connect to that server?
I tried subprocess and spur, however I didn't really manage to get that going.
I would really appreciate your help and thanks in advance.
assuming the python prints the settings to stdout;
#!/bin/sh
export $(credentials.py)
exec ssh hostname
On machine A I want to have a small python script to execute a command on machine B. Machine A is Windows with freesshd running on it, and machine B can be either Windows or Linux. I only have a username and a password to log in to machine B, no other way of authentication.
How can I create a python script to run a command on machine B? ssh would be fine, but where to find that command on Windows? And it has to be done without paramiko, since this module does not wok for unknown reasons.
If you can't get paramiko working, just do it manually with Popen: http://python-for-system-administrators.readthedocs.org/en/latest/ssh.html
I haven't tried this on Windows but to handle input and output of a command pexpect is a good candidate. It also has a ssh part http://pexpect.readthedocs.org/en/latest/api/pxssh.html.
Did some more digging. There is a windows port of pexpect: https://gist.github.com/anthonyeden/8488763
Use that along with putty on the command line in windows.
Example of Putty on command line: http://etherealmind.com/putty-command-line/
I would like to achieve the following things:
Given file contains a job list which I need to execute one by one in a remote server using SSH APIs and store results.
When I try to call the following command directly on remote server using putty it executes successfully but when I try to execute it through python SSH programming it says cant find autosys.ksh.
autosys.ksh autorep -J JOB_NAME
Any ideas? Please help. Thanks in advance.
Fabric is a good bet. From the home page,
Fabric is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
A quick example,
>>> from fabric.api import run, env, cd, settings, hide, show
>>> env.host_string='xxx.xxx.com'
>>> env.user='user'
>>> env.password='password'
>>> run('ls -lart')
After reading your comment on the first answer, you might want to create a bash script with bash path as the interpreter line and then the autosys commands.
This will create a bash shell and run the commands from the script in the shell.
Again, if you are using autosys commands in the shell you better set autosys environment up for the user before running any autosys commands.
I've been using Paramiko today to work with a Python SSH connection, and it is useful.
However one thing I'd really like to be able to do over the SSH is to utilise some Pythonic sugar. As far as I can tell I can only use the inbuilt Paramiko functions, and if I want to anything using Python on the remote side I would need to use a script which I have placed on there, and call it.
Is there a way I can send Python commands over the SSH connection rather than having to make do only with the limitations of the Paramiko SSH connection? Since I am running the SSH connection through Paramiko within a Python script, it would only seem right that I could, but I can't see a way to do so.
RPyC could be what you're looking for. It gives you access to another machine's Python environment directly from the local script.
>>> import rpyc
>>> conn = rpyc.classic.connect("someremotehost.com")
>>> conn.modules.sys.path
['D:\\projects\\rpyc\\servers', 'd:\\projects', .....]
To establish a connection over SSL or SSH, see:
http://rpyc.sourceforge.net/docs/secure-connection.html#ssl
Well, that is what SSH created for - to be a secure shell, and the commands are executed on the remote machine (you can think of it as if you were sitting at a remote computer itself, and that either doesn't mean you can execute Python commands in a shell, though you're physically interact with a machine).
You can't send Python commands simply because Python do not have commands, it executes Python scripts.
So everything you can do is a "thing" that will make next steps:
Wrap a piece of Python code into file.
scp it to the remote machine.
Execute it there.
Remove the script (or cache it for further execution).
Basically shell commands are remote machine's programs themselves, so you can think of those scripts like shell extensions (python programs with command-line parameters, e.g.).