Repository: spyder-ide/spyder

Issue:
Freeze when connecting to remote kernel via SSH with protected key file
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
While it works flawlessly on win10, on my Linux box spyder could not connect to a remote kernel via ssh with a private key. I reproduced the problem in a standalone qtconsole, see jupyter/qtconsole#480. From there, I figured out that the regex used to catch the password prompt has an issue in qtconsole on my system, exactly as in jupyter/jupyter_client#494. I could fix this for qtconsole by removing the column in the regex of the [source](https://github.com/jupyter/jupyter_client/blob/master/jupyter_client/ssh/tunnel.py#L60).
However, spyder seems to have its own implementation of establishing the ssh tunnel, so fixing qtconsole did not fix spyder. I had to change the regex [here](https://github.com/spyder-ide/spyder/blob/master/spyder/plugins/ipythonconsole/utils/ssh.py#L62), since my system prompts for the password like `SSH passphrase for user@ip:`, so the regex `[Pp]assword:` caused spyder to hang as it never matched. Changing the regex to `[Pp]assphrase` did the trick and I can now enjoy remote kernels from within spyder :) I really hope somebody sees this before they have to go on the same adventure that I had!

### What steps reproduce the problem?

1. Use GUI dialog to set up ssh connection to remote kernel using a pem keyfile and passphrase
2. Click "OK"

### What is the expected output? What do you see instead?
Expected a terminal tab opening for the new connection. Instead, spyder completely freezes and has to be sigkilled.


```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 5.0.0
* Python version: 3.8.8 amd64
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Arch Linux 5.11

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  3.0.4 (OK)
cloudpickle >=0.5.0           :  1.6.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.22.0 (OK)
jedi =0.17.2                  :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  22.3.0 (OK)
nbconvert >=4.0               :  6.0.7 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
parso =0.7.0                  :  0.7.0 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.8.1 (OK)
pylint >=1.0                  :  2.7.4 (OK)
pyls >=0.36.2;<1.0.0          :  0.36.2 (OK)
pyls_black >=0.4.6            :  0.4.6 (OK)
pyls_spyder >=0.3.2           :  0.3.2 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=0.5.7             :  1.0.2 (OK)
qtconsole >=5.0.3             :  5.0.3 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.8.3                 :  0.9.7 (OK)
setuptools >=39.0.0           :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                :  3.5.3 (OK)
spyder_kernels >=2.0.1;<2.1.0 :  2.0.1 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3;<2.0.0      :  1.0.2 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  20.0.0 (OK)

# Optional:
cython >=0.21                 :  0.29.23 (OK)
matplotlib >=2.0.0            :  3.3.4 (OK)
numpy >=1.7                   :  1.19.5 (OK)
pandas >=1.1.1                :  1.2.4 (OK)
scipy >=0.17.0                :  1.6.2 (OK)
sympy >=0.7.3                 :  1.8 (OK)
```



Discussion:
> I could fix this for qtconsole by removing the column in the regex of the source.

Ok, I'll create a pull request for your suggested changed there. We also maintain that project, so we can merge it and include it in the next Qtconsole release.

> Changing the regex to [Pp]assphrase did the trick and I can now enjoy remote kernels from within spyder

Great! I'll include your change in our next release so other people can benefit from it in Spyder too.
@green-slowmoe, instead of replacing `'[Pp]assword:'`, could you test this change?

```python
i = tunnel.expect([ssh_newkey, '[Pp]assword:', '[Pp]assphrase'], timeout=.1)
```

I just want to double check with you before committing it because I don't have a way to test it.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole/utils/ssh.py b/spyder/plugins/ipythonconsole/utils/ssh.py
--- a/spyder/plugins/ipythonconsole/utils/ssh.py
+++ b/spyder/plugins/ipythonconsole/utils/ssh.py
@@ -59,7 +59,10 @@ def openssh_tunnel(self, lport, rport, server, remoteip='127.0.0.1',
     failed = False
     while True:
         try:
-            i = tunnel.expect([ssh_newkey, '[Pp]assword:'], timeout=.1)
+            i = tunnel.expect(
+                [ssh_newkey, '[Pp]assword:', '[Pp]assphrase'],
+                timeout=.1
+            )
             if i == 0:
                 host = server.split('@')[-1]
                 question = _("The authenticity of host <b>%s</b> can't be "


Test patch: