Magisk-Modules-Repo / ssh

ssh
181 stars 34 forks source link

For those who can't get public key authentication working #32

Closed Ryuo1 closed 1 year ago

Ryuo1 commented 2 years ago

First generate a key pair using ssh-keygen

  1. Get the public key (assuming it's named _idrsa.pub) from your computer (in $HOME/.ssh/ folder assuming you are on Linux), to your phone.

  2. Copy the contents of your public key inside your phone using root browser's text editor or any other text editor of your choice.

  3. Create a file named _authorizedkeys inside the /data/ssh/root/.ssh/ folder.

  4. Paste the contents of your public key into the _authorizedkeys file using the text editor of your choice.

  5. Copy that file into the /data/ssh/shell/.ssh/ folder if you want shell login too.

  6. Now to login into your phone using ssh, you need the private key (assuming it is named _idrsa) that was generated with your public key. Type this command onto your computer in the same folder as your private key file. ssh -i id_rsa root@[_your phone's local ip_]. You don't need to type the -i id_rsa if you private and public key file is in your computer's $HOME/.ssh/ folder.

You got yourself a perfectly functioning key with right permissions! (Unless you didn't follow the instructions correctly)

ReMiOS commented 2 years ago

I can't get SSH key working ( tried installing v0.14 and v0.13)

Running Magisk 24.1 and Android 10

Error when i try to login: Server refused our key No supported authentication methods available (server sent: publickey,keyboard-interactive)

I am positive the key is working since the same key is working on my old phone

star2lte:/data/ssh/root/.ssh # ls -al drwx------ 2 root root 4096 2022-02-21 22:34 . -rw------- 1 root root 398 2022-02-21 22:34 authorized_keys

Ryuo1 commented 2 years ago

Which key did you copy to your phone? the public key or the private key?

Ryuo1 commented 2 years ago

@ReMiOS Oh and you shouldn't directly copy the key to your phone. The key contents should be copied, and then inside your phone you create the file named _authorizedkeys and paste what you copied from your public key, to inside the file in your phone.

ReMiOS commented 2 years ago

Found it !

I noticed i can login when i hop from a linux server to my phone ( added that ssh key too )

So it had to be something with the SSH client.

I've upgraded my MobaXterm SSH client from v20.3 to v21.5 and now i can login directly as well

Probably due to the upgraded OpenSSL / OpenSSH

Shadow27374 commented 2 years ago

I had to do this: https://www.cnx-software.com/2012/07/20/how-use-putty-with-an-ssh-private-key-generated-by-openssh/

and it works with Putty.

Unfortunately it does not work with MobaXterm 21.2.