Skip to contentSkip to conversation

tests/vm: use -o IdentitiesOnly=yes for ssh

PATCH In review Ilya Leoshkevich 3 participants 3 messages Oct 27, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/vm: use -o IdentitiesOnly=yes for ssh

When one has a lot of keys in ~/.ssh directory, the ssh command will try all of them before the one specified on the command line, and this may cause the remote ssh server to reject the connection due to too many failed authentication attempts.

Fix by adding -o IdentitiesOnly=yes, which makes the ssh client consider only the keys specified on the command line.

---
 tests/vm/basevm.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/vm/basevm.py +2 -1
index 4fd9af10b7f..2276364c42f 100644
@@ -233,7 +233,8 @@ def _ssh_do(self, user, cmd, check):
                    "-o", "UserKnownHostsFile=" + os.devnull,
                    "-o",
                    "ConnectTimeout={}".format(self._config["ssh_timeout"]),
-                   "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file]
+                   "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file,
+                   "-o", "IdentitiesOnly=yes"]
         # If not in debug mode, set ssh to quiet mode to
         # avoid printing the results of commands.
         if not self.debug:
Signature · 1 line
2.37.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Ilya Leoshkevich

When one has a lot of keys in ~/.ssh directory, the ssh command will try all of them before the one specified on the command line, and this may cause the remote ssh server to reject the connection due to too many failed authentication attempts.

Fix by adding -o IdentitiesOnly=yes, which makes the ssh client consider only the keys specified on the command line.

---
  tests/vm/basevm.py | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tests/vm/basevm.py +0 -0
index 4fd9af10b7f..2276364c42f 100644

tests/vm/basevm.py def _ssh_do(self, user, cmd, check): · line 240

Quoted 9 lines
tests/vm/basevm.py +2 -1
@@ -233,7 +233,8 @@ def _ssh_do(self, user, cmd, check):
                     "-o", "UserKnownHostsFile=" + os.devnull,
                     "-o",
                     "ConnectTimeout={}".format(self._config["ssh_timeout"]),
-                   "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file]
+                   "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file,
+                   "-o", "IdentitiesOnly=yes"]
          # If not in debug mode, set ssh to quiet mode to
          # avoid printing the results of commands.
          if not self.debug:

Ah, great, I've run into this problem in the past already, too, but I didn't find that config switch! Good to know that there is a solution!

#2 lore raw
In reply to Ilya Leoshkevich
Quoted 9 lines · Ilya Leoshkevich

When one has a lot of keys in ~/.ssh directory, the ssh command will try all of them before the one specified on the command line, and this may cause the remote ssh server to reject the connection due to too many failed authentication attempts.

Fix by adding -o IdentitiesOnly=yes, which makes the ssh client consider only the keys specified on the command line.

Queued to testing/next, thanks.

Signature · 1 line
Alex Bennée