Jason Donnald
Jason Donnald

Reputation: 2316

error in executing a remote python script from local python script

I have a local python script through which I am trying to execute a remote python script but I am getting errors. This is the code in my local python script:

cmd_txt = "ssh -v -i /home/user/pem_file.pem user@" + host_name + " 'cd /home/test/ && python python_file.py "+ argument1 +" "+ arguent2 +"'"

system(cmd_txt)

The console output and error is:

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug1: Connecting to _ port 22.
debug1: Connection established.
debug1: identity file /.ssh/id_rsa type 1
debug1: identity file /.ssh/id_rsa-cert type -1
debug1: identity file /id_dsa type -1
debug1: identity file /id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'hostname' is known and matches the RSA host key.
debug1: Found key in .ssh/known_hosts:13
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: .ssh/id_dsa
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: Device not configured
debug1: permanently_drop_suid: 502
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: Device not configured
debug1: permanently_drop_suid: 502
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: Device not configured
debug1: permanently_drop_suid: 502
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

When I execute the ssh command from the command line I do not get error but from within the python script it throws error. One thing to note is that when I execute it from terminal I get a notification to enter a password but from python I do not get anything nor do I know how to pass the password alongwith ssh.

Also, the remote python script in turn contains another ssh call for a java jar execution. the structure of that call is similar to above ssh call.

What am doing wrong here and how to resolve this issue? `

Upvotes: 1

Views: 548

Answers (1)

SillyWilly
SillyWilly

Reputation: 388

Your public key authentication isn't working. That's why when you try the command in the terminal it asks for your password. This line in the log indicates the order of authentication methods it will try:

Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password

You see how password is the last one, so if all else fails, it falls back on that.

When you try and do this from the Python script, it's unable to start an interactive process to ask you for the password so it fails completely. That's what this line means:

debug1: read_passphrase: can't open /dev/tty: Device not configured

You need to fix the public key authentication so it works when you ssh from a terminal before you try to make it work from a Python script.

Upvotes: 1

Related Questions