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

Fix EOF: command not found error in ssh-copy-id #206

Closed
wants to merge 1 commit into from

Conversation

Fallmay
Copy link
Contributor

@Fallmay Fallmay commented Oct 1, 2020

At the moment, the ssh-copy-id utility is not working properly.

$ ssh-copy-id user@hostname
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 2 key(s) remain to be installed -- if you are prompted now it is to install the new keys
/usr/bin/ssh-copy-id: line 251: warning: here-document at line 251 delimited by end-of-file (wanted `EOF')
/usr/bin/ssh-copy-id: line 250: warning: here-document at line 250 delimited by end-of-file (wanted `EOF')
/usr/bin/ssh-copy-id: line 254: /dev/null`: Permission denied
/usr/bin/ssh-copy-id: line 260: EOF: command not found

OpenSSH 8.4/8.4p1 (2020-09-27).

@3eka
Copy link

3eka commented Oct 1, 2020

Hi,
this might depend on OS (just guessing).
On Linux /bin/sh is sym-linked to /bin/bash which is not case everywhere.
For example, I have to change /bin/sh to /bin/bash on OpenIndiana to get ssh-copy-id working (no errors; last one from 8.4p1).

Regards.

@daztucker
Copy link
Contributor

ssh-copy-id is contributed by Phil Hands, its upstream is at https://gitlab.com/phil_hands/ssh-copy-id/-/tree/main

@phil-hands
Copy link

Which shell/OS was it that threw this error?

I'm asking becuase it occurs to me that it may be better to detect that shell in a way similar to the initial 'if false " ...' test for the old Solaris shell, and then hunt for something better.

However, I suspect that the suggested patch is pretty portable, so probably easier to go with that.

BTW /bin/sh is not always a symlink to /bin/bash on Linux -- that is dependant on the distribution. Debian uses dash as the default /bin/sh, for instance.

@daztucker
Copy link
Contributor

daztucker commented Oct 1, 2020

Aside:

/usr/bin/ssh-copy-id: line 254: /dev/null`: Permission denied

if your /dev/null is not world writable (or isn't a character special file) then many things are going to be sad.

@Jakuje
Copy link
Contributor

Jakuje commented Oct 2, 2020

Aside:

/usr/bin/ssh-copy-id: line 254: /dev/null`: Permission denied

if your /dev/null is not world writable (or isn't a character special file) then many things are going to be sad.

I don't think the /dev/null is not writable. I think this is an after-effect of wrong parsing of the script and in this attempt, it tries to execute the /dev/null as a program, which obviously on any sane system fails.

@Fallmay
Copy link
Contributor Author

Fallmay commented Oct 2, 2020

Which shell/OS was it that threw this error?

I'm asking becuase it occurs to me that it may be better to detect that shell in a way similar to the initial 'if false " ...' test for the old Solaris shell, and then hunt for something better.

However, I suspect that the suggested patch is pretty portable, so probably easier to go with that.

BTW /bin/sh is not always a symlink to /bin/bash on Linux -- that is dependant on the distribution. Debian uses dash as the default /bin/sh, for instance.

Fedora 33 (Workstation Edition Prerelease).

@Jakuje
Copy link
Contributor

Jakuje commented Oct 2, 2020

Maybe more important what shell is your default and what is your /usr/bin/sh symlinked to.

@Fallmay
Copy link
Contributor Author

Fallmay commented Oct 2, 2020

Maybe more important what shell is your default and what is your /usr/bin/sh symlinked to.

$ echo "$SHELL"
/bin/bash
$ ls -l /bin/sh /usr/bin/sh
lrwxrwxrwx. 1 root root 4 Jul 27 16:18 /bin/sh -> bash
lrwxrwxrwx. 1 root root 4 Jul 27 16:18 /usr/bin/sh -> bash

@Jakuje
Copy link
Contributor

Jakuje commented Oct 2, 2020

Oh, right, I see it also with default bash in my test, but I somehow managed to miss this issue.

@georgmu
Copy link

georgmu commented Oct 2, 2020

I don't understand how this has to do with bash vs. sh. This is an obvious shell error and I want to see any shell which interprets this correct.

To reduce the problem, execute the following command:

echo $(cat <<-EOF)

It is wrong to close the subshell before the EOF end marker

@georgmu
Copy link

georgmu commented Oct 2, 2020

Ok, I tried it with dash and there it works.

bash accepts

(cat << EOF)
foo
EOF

but not

FOO=$(cat <<EOF)
foo
EOF

dash accepts both.

@phil-hands
Copy link

Ah, righto -- It seems that I've somehow managed to do all of my testing with dash. That was careless.

I'll add a few more shells to my tests, and then fix this as suggested.

Thanks for the report :-)

@phil-hands
Copy link

This is now included in my repo:

https://gitlab.com/phil_hands/ssh-copy-id/-/tree/main

so the pull request here is no longer needed.

Thanks again to you all for helping make ssh-copy-id better.

@daztucker
Copy link
Contributor

I have pulled this change (and a couple of subsequent ones) from Phil's repository. Thanks all.

@daztucker daztucker closed this Oct 2, 2020
mhoyer added a commit to mhoyer/MSYS2-packages that referenced this pull request Oct 27, 2020
After update of git-for-windows to 2.29.1 a newer version of openssh 8.4p1 was included as well. This version contains a bug in the ssh-copy-id script (see: openssh/openssh-portable#206).

This commit fixes git-for-windows/git#2873

Signed-off-by: Marcel Hoyer <[email protected]>
@gustavorv86
Copy link

gustavorv86 commented Nov 8, 2020

It's perfect!

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/user/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
/usr/bin/ssh-copy-id: line 251: warning: here-document at line 251 delimited by end-of-file (wanted `EOF')
/usr/bin/ssh-copy-id: line 250: warning: here-document at line 250 delimited by end-of-file (wanted `EOF')
/usr/bin/ssh-copy-id: line 260: EOF: command not found

I fixed the problem in Cygwin with openssh 8.4p1-1 package.

Thank you!

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

Successfully merging this pull request may close these issues.

7 participants