Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paramiko should ignore LOGNAME #2096

Open
asomers opened this issue Jul 29, 2022 · 0 comments
Open

Paramiko should ignore LOGNAME #2096

asomers opened this issue Jul 29, 2022 · 0 comments

Comments

@asomers
Copy link

asomers commented Jul 29, 2022

Paramiko currently uses getpass.getuser() to determine the local username, which works by examining various environment variables, starting with LOGNAME. However, that can give the wrong answer following su. For example:

> sudo su -m nobody
su: /root/.bashrc: Permission denied
[nobody@myhost /mydirectory]$ echo $LOGNAME
root

This leads to authentication errors, at least when using hostbased authentication as in PR #2093, like this: paramiko.ssh_exception.AuthenticationException: /usr/libexec/ssh-keysign terminated with an error: not a valid request. I haven't yet figured out how to trigger the problem without hostbased authentication, but config.py and client.py both use getpass.getuser().

OpenSSH itself does not. It uses the process's uid. See https://github.com/freebsd/freebsd-src/blob/150486f6a940947fa7a7c6db357c3f92d07a955f/crypto/openssh/ssh.c#L660 . I suggest that Paramiko do the same. Doing that fixes the hostbased authentication errors after su. Do you agree? the Python code is

username = pwd.getpwuid(os.getuid()).pw_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants