I'm using a rooted custom Android kernel (Gingerbread), and am able to connect to a remote SSH server with password authentication using busybox and a terminal emulator app. I would like to be able to use SSH keys for auto-login; is this possible? If so, where should I put my private key?
2 Answers
It's not quite as seamless, but the ssh
binary provided by busybox (mine, at least) supports the -i
flag, so you can put the key wherever you want and use that:
ssh -i /path/to/key_file [email protected]
The relevant man page entry for -i
(with the caveat that the information about the default path may not be the same on Android):
-i identity_file
Selects a file from which the identity (private key) for public
key authentication is read. The default is ~/.ssh/identity for
protocol version 1, and ~/.ssh/id_dsa, ~/.ssh/id_ecdsa and
~/.ssh/id_rsa for protocol version 2. Identity files may also be
specified on a per-host basis in the configuration file. It is
possible to have multiple -i options (and multiple identities
specified in configuration files). ssh will also try to load
certificate information from the filename obtained by appending
-cert.pub to identity filenames.
-
Thanks, I had thought of that, but never got around to trying it. It just seems strange that there is no place that the ssh command will look for the .ssh directory... maybe it's because there is no $HOME set? Commented Apr 27, 2012 at 13:59
-
2@Yuttadhammo: The weird thing is that
$HOME
(for root) is set to/data
on my phone, butssh
seems to ignore any directories I try to set up there. I've never really figured out why that is, but I haven't had a need to really dig into it, either. Commented Apr 27, 2012 at 14:20 -
@Yuttadhammo In my phone,
echo $HOME
returns nothing (even for root). If that's your case too, its the reason why your SSH client can't see keys by default. But, with-i
flag, you can override the default path, so there's no point of looking $HOME. This is the correct solution if your trimmed down SSH client supports it. So, try it after putting keys on sdcard. If it fails, there's no other way unless you change SSH client. Commented Apr 28, 2012 at 9:07 -
Install & run ConnectBot (a dedicated SSH client). Tap/press menu key. From the menu, tap Manage Pubkeys
. On next screen, again press/tap menu key. From the menu, tap Import
.
-
Thanks I actually just did that - nice app; is there no way to simply put a key somewhere and have busybox pick it up? Commented Apr 27, 2012 at 6:17
-
@Yuttadhammo I don't think default packaging of Busybox provide SSH client. Can you be more specific with your SSH client (which may be external utility)? Commented Apr 27, 2012 at 11:39
-
Also, remember.. as busybox applets are trimmed down version of original ones, your command line SSH client may not support authentication with key, but its very unlikely. Just tell me about your SSH client. Commented Apr 27, 2012 at 11:40
-
Thanks, ConnectBot is the solution I'll be using, but the -i flag is really closer to answering the question. Commented Apr 28, 2012 at 12:07