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

Dual Authentication (Key + Password) #456

Open
sevsev9 opened this issue Jan 29, 2025 · 3 comments
Open

Dual Authentication (Key + Password) #456

sevsev9 opened this issue Jan 29, 2025 · 3 comments

Comments

@sevsev9
Copy link

sevsev9 commented Jan 29, 2025

Hi!

I've been trying to get SFTP to work with a server that requires both key and username/password authentication, but I can't seem to make it work.

I've been combing through the examples and the docs.rs (client::Config, etc.) but I can't seem to figure it out.

Is this feature currently supported? Has anyone done it before?

Any help would be greatly appreciated.

Thanks!

OpenSSH Server Configuration

  1. /etc/ssh/sshd_config:
PasswordAuthentication yes
PubkeyAuthentication yes
AuthenticationMethods publickey,password

Restart the SSH service:

sudo systemctl restart ssh
  1. Running SSH manually on the same machine works fine:
ssh -i /path/to/private_key [email protected]

Environment:

  • russh crate version: 0.49
  • russh-sftp crate version: 2.0.6
  • russh-keys crate version: 0.49
  • Rust version: rustc 1.86.0
  • OS: Ubuntu 24.04 LTS
  • SSH Server: OpenSSH_8.9p1
@Eugeny
Copy link
Owner

Eugeny commented Jan 29, 2025

Hard to say without the code, but you don't need to do anything except call authenticate_password, receive the expected Ok(false), and then call authenticate_publickey

@sevsev9
Copy link
Author

sevsev9 commented Feb 1, 2025

Thanks! I've got it working almost as you said (first key, then password). Should I maybe distil an example for this?

@Eugeny
Copy link
Owner

Eugeny commented Feb 1, 2025

I'd say it's implementation specific as the SSH protocol has no actual provision for requiring multiple authentication methods.
There is no physical distinction between the server rejecting the key because it's wrong and rejecting it because it's right but it needs a password too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants