Step to reproduce:
1.- Add a space at the end of IdentityFile line in ~/.ssh/config file
2.- Connect to this host using standard ssh: Everything is ok
2.- Try to connect to this host using paramiko: Error raises:
BackendException: ssh connection to root@xxxxxxx:22 failed: [Errno 2] No such file or directory: '/home/xxxxxx/.ssh/id_rsa '
Thought I saw a recent patch about trailing whitespace, can't find it but still looking.
Did find #375 which implies we did want this behavior but there's no actual rationale listed...
EDIT: yea, there's a test that #375 was just making sure didn't get accidentally broken: https://github.com/paramiko/paramiko/blob/ade0c259ee1ad630a53998c77ce1d852e417aa50/tests/test_util.py#L113 - walking down the blame on that line leads me back to 02e8178 ca 2006 by robey, which clearly means it's been "intended" behavior since the beginning of the codebase or near enough.
May dig farther in case there is rationale but usually code that old doesn't have a solid reason in the commit message. I honestly can't think of many reasons why trailing whitespace is something anybody wants, and as per #653's investigation, OpenSSH itself performs trailing whitespace stripping.
Pondering whether we should be super careful re: backwards compat, and fix this in the upcoming 2.0 release. But my gut says it's probably hurting many more people than it could possibly be helping, so maybe treating as a regular bug is the right approach.
Yea I can't find the patch I was remembering so I'm probably crazy or it was posted to another tracker. @56quarters if you want to draft a PR as follows, I'd merge it:
Thanks for the guidance @bitprophet, I'll probably come up with a PR this weekend.
PR that fixes this: #656
Update SSHConfig.parse to strip leading and trailing whitespace
Changelog re #499, re #656