Skip to content

The ProcessShellCommandFactory does not support ssh-copy-id and multi-command execution. #899

@yuhJohn

Description

@yuhJohn

Question 1:
The ssh-copy-id command is not supported. This is actually a standard command for ssh.
clientInput:
ssh-copy-id -p 123 -i /root/.ssh/id_rsa.pub user@ip

and received the following command
exec sh -c'cd; umask 077; mkdir -p \".ssh\" && {[-z tail -1c .ssh/authorized_keys 2>/dev/null] || echo >> \".ssh/authorized_keys\" || exit 1;} && cat >> \".ssh/authorized_keys\" || exit 1; if type restorecon >/dev/null 2>&1; then restorecon -F \".ssh\" \".ssh/authorized_keys\"; fi'

The exec cannot be identified. As a result, the execution fails.
I solved this by customizing exec judgment.

    public Command createCommand(ChannelSession channel, String command) throws IOException {

        LOGGER.error("create Command: " + command);

        if (command !=null && command.startsWith("exec ")) {
            command = command.substring(5);
        }

        return new ShellWrapperCommand(command);
}

Question 2: Multiple commands such as " ls -l; rm -rf /tmp/test" cannot be executed correctly.
The input is as follows:
ssh user@IP -p 123 "echo test2; echo 22"

The actual output is
test2; echo 22

I understand that the preceding two questions are very common scenarios. Is SSHD not supported by default?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue describing a bug in the code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions