reddit / emacs

using Tramp without password

Schievel1 · 2022-09-13 14:40
Today I connected with "ssh root@x.y.z.ip" (in the terminal) to an embedded system. Don't ask why it's root, I didn't do this. When I connected it asked me if I want to accept the servers fingerprint. And that was that, connected. I never connected to this machine before, so it certainly has no ssh keys from me. In fact the WSL I was doing this from didn't even have a ssh Gen generated. Using Tramp in emacs with C-x C-f /ssh:x.y.z.ip:/ it asks me for a password. Problem is, I don't know the password. So, I tried generating a ssh key on my WSL machine and transfered it into /home/root/.ssh/authorized_keys, but that didn't help either. SIC! about the directory (although I don't not know if I did something wrong.) Does anyone know how to pull this off?
anaumann · 2022-09-13 15:02
connecting as root@somewhere and just plain somewhere is kind of different ;) You could try opening /ssh:root@x.y.z.ip:/ instead of omitting the username.. Connecting as root kind of worked after all.. If you put the key manually into the authorized\_keys file, there are a few pitfalls in regard to file and folder permissions that could have happened(and that are preventing you from connecting with that key).. the ssh-copy-id comment is usually the safer way of doing that :) And last but not least: Did you enter a passphrase for your generated key? If yes, you'd need to enter that when connecting.. Only with a passphrase-less key and the key being in $HOME/.ssh/authorized\_keys and $HOME.ssh and $HOME.ssh/authorized\_keys having the correct permisssions, will it let you connect... ...and some scolding about trying to connect passwordless without using ssh-agent :D
Schievel1 · 2022-09-13 15:14
Well this thing is a development board, and I guess the developer who did this didn't want to get calls asking for the password all the time :D Oh yeah /ssh:root@ip:/ didn't cross my mind. When I connected via /ssh:ip:/ it asked me for a username and I provided root though. Maybe it was already in the connect via password rail then. Didn't enter a password for the key. When I tried ssh-copy-id root@ip it just hang until I CTRL-C'ed it
Trout_Tickler · 2022-09-13 15:50
Create an entry in `~/.ssh/config` that looks like Host board HostName ip IdentityFile path-to-ssh-key User root Then you can do `/ssh:board:/`
mickeyp · 2022-09-13 16:28
Yes, this is the only scalable way to manage this. As an addendum to this: use `C-x r m` to bookmark the dired instance (or from inside `M-x eshell` or a file) and you instantly return to it later with `C-x r l`
noman_032018 · 2022-09-13 17:02
Other comments, particularly the one about `ssh_config` are on point, but I also need to ask, did you use `ssh-add` so that your ssh_agent is aware of the key you just generated? If you haven't and the agent isn't aware, then without configs there is simply no way for TRAMP to use that key. If you manage many machines, I would also recommend learning about SSH's Certificate/CA features. There are a lot of uses for it such as constraining just what any given certificate can do on which machine and as which users. edit: If `root` connection is not directly allowed on the remote host, [TRAMP also supports connections with hops](https://www.gnu.org/software/tramp/#Ad_002dhoc-multi_002dhops).
anaumann · 2022-09-13 17:09
Is it something odd with a mini-Linux on it or a network device or something? ssh-copy-id should usually work just fine and the only time I've had problems with tramp was when I started using oh-my-zsh.. I'm connecting via sshx instead of ssh now.
db48x · 2022-09-13 17:24
You can use `ssh -v root@…` to investigate how you were authenticated. It may simply not require any authentication. You are specifically looking for messages that look like this: debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey Alternatively, log in to the machine and examine `/etc/ssh/sshd_config`.
Schievel1 · 2022-09-13 18:18
Littlebut odd I guess. Yocto Linux on a control system Hm I'm using oh my zsh, so I will give sshx a try
anaumann · 2022-09-13 18:47
Problems with oh-my-zsh fancy prompts usually show themselves with tramp connecting just fine and then waiting on a prompt until hitting a timeout.. So it must be something different, but for tramp, sshx is ok most of the time, it just needs a shell to bounce commands off of, nothing fancy :D
Schievel1 · 2022-09-13 19:29
Thanks for all the input. I will have a look on thursday / edit: /ssh:root@x.y.z.ip:/ works
Trout_Tickler · 2022-09-13 19:51
`consult-dir` also handles these!
physix4 · 2022-09-14 11:17
Given that it is an embedded system (likely built with Buildroot or Yocto), I would bet that there is no authentication.
Schievel1 · 2022-09-15 06:33
Just a quick follow: /ssh:[root@x.y.z.ip](mailto:root@x.y.z.ip):/ works fine. Now I feel like I am an idiot. Thanks for your help.
tungd · 2022-09-15 10:58
Another option is authinfo file, with the added benefit that it will also work for non-ssh connections, and you will be able to encrypt the file transparently with GPG. The tradeoff is that you can only use password and not key file. See: https://www.gnu.org/software/emacs/manual/html_node/emacs/Authentication.html