holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.72k stars 117 forks source link

ssh-copy-id fails with redirect error #754

Open tthkbw opened 7 months ago

tthkbw commented 7 months ago

ssh-keygen seems to work ok, but when I try to use ssh-copy-id, I get this:

warning: An error occurred while redirecting file '/dev/null` ] || echo >> .ssh/authorized_keys || exit 1; } && cat >> .ssh/authori zed_keys || exit 1; if type restorecon >/dev/null 2>&1; then restorecon -F .ssh .ssh/authorized_keys; fi'

Any help?

holzschu commented 7 months ago

That's a tough one. If I read the source code correctly, that command is executed on the host, so the most likely answer is that the host does not allow redirection to "/dev/null".

tthkbw commented 7 months ago

The host is a MacBook Air M2 running Sonoma 14.3.1. When I execute

echo “hello, dev null” > /dev/null”

On the host, I see no issues.

I am running a-shell on an iPad Pro 12.9 3rd generation running iPadOS 17.4.

I’m pretty sure at one time I had ssh running without requiring a password from a-shell. But for awhile now I haven’t been able to. I hoped that the new ssh-copy-id command would solve my issues.

holzschu commented 7 months ago

I tried on my own MacBook Air, and it works. The thing is, ssh-copy-id needs to be able to connect to the other machine (using another ssh key, usually) in order to copy the new ID. If you cannot already connect with ssh, ssh-copy-id will not work.

tthkbw commented 7 months ago

I am able to log in to my MacBook Air from my ipad using a-shell--it just asks for the password. Same for using sftp and other commands.

I think that you are trying this running a-shell on your MacBook??

So I tried that and got the same error. Then I thought, why not try another machine? So I tried using ssh-copy-id while using a-shell on my Air but connecting to my macmini. When I ssh-ed into the macmini first to be sure it worked, I realized that the macmini was using zsh as my shell because it asked to update. I went through the procedure and voila! ssh-copy-id worked perfectly and I could ssh without a password.

My default shell on the Air is fish. Then I realized that this issue probably started after I began using fish as my shell, which was probably shortly after getting the new MacBook Air M2. So, I thought, let's try changing the shell to see it that fixes the problem connecting to the Air.

It did! By changing the default shell to zsh, a-shell's ssh-copy-id does not fail and everything works as expected. Then I changed the default shell back to fish and it still works--which makes sense.

I suspect the failure has something to do with the fact that fish is installed using Homebrew and its path is /opt/homebrew/bin/fish rather that /bin/fish. Why this affects redirects to /dev/null, when fish does support this, I have no idea, but macos does comment that fish shell is a non-standard shell--probably because it does not come with macOS.

Anyway, others may have this issue as well, and I hope they find this solution!