I had setup passwordless ssh (keygen) to access my remote workspace from my personal laptop. On the remote server, I do use an account with a password to connect. Setting up public/private key authentication allowed me to connect without having to type this password.

The Python script I am running uses subprocess.Popen() to ssh into this remote workspace again. However, it is not a passwordless ssh during this. I have checked my permissions and have tried to delete and recreate the keys, yet this still happens.

Below is the relevant piece of Python code.

subprocess.Popen(['ssh', machine_addr, 'cd ' + workspace + \ '; python dispynode.py --serve 1 --clean --dest_path_prefix dispytmp_' + str(i)])

  • What do you mean when you say passwordless? The account you are trying to log in is really passwordless? Are you using ip based authentication? Are you using public/private key authentication?
    – andcoz
    Jun 14, 2018 at 15:23
  • I have clarified what I meant by passwordless. I am using key authentication.
    – jg925
    Jun 14, 2018 at 15:25
  • 1
    Is your key passphrase protected? Is the password ssh asks the remote host password or the key passphrase?
    – andcoz
    Jun 14, 2018 at 15:41
  • Before I set up the keys, I used a password to access the server.
    – jg925
    Jun 14, 2018 at 16:05
  • 1
    Are you using ssh-agent on the client to manage the SSH keys? If so, are you executing the Python script in an environment where the SSH_AUTH_SOCK environment variable is available? Are you executing your Python script as yourself or as another user?
    – Kusalananda
    Jun 14, 2018 at 16:09

1 Answer 1


I know this question has been asked 4 years ago but I faced the same problem and found an explanation and a solution which worked for me, so this might be helpful for other people in the same situation.


Same as you, I generated and shared the ssh keys between my client (Raspberry Pi) and my server. I was able to connect via ssh with no password prompt running ssh user@server. But when my Python script tried to connect with subprocess.Popen, it asked for a password.


The thing is I run my Python script with sudo because for some reasons I need to.

So the ssh command ran by subprocess.Popen used as ssh key the one located at /root/.ssh/id_rsa, while the one generated and shared with the server was located at /home/user/.ssh/id_rsa.


Add as argument to the ssh command the correct identification file :

ssh -i /home/user/.ssh/id_rsa user@server

So the Python line you need is the following :

subprocess.Popen(['ssh', '-i', '/home/user/.ssh/id_rsa', 'user@server']

To which you add the commands you want (cd, mkdir, etc).

Hope this helps !

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .