Im using ssh with a system that has a lot of security settings. The bash command I want to run is:
ssh –t user@address su –c ‘echo “user ALL=(ALL) NOPASSWD:ALL” >> /etc/sudoers.d/permissions’
This command does not work since su does not recognize the stuff after it as a command. EOF is disabled by default for ssh and EOSU is disabled by default on all computers in the network. Sudo is also disabled for the user on the host computer. Is there a clean way to do this while calling su as little as possible?
Note: I already did keygen stuff so the ssh login is passwordless, root login through ssh is disabled by default.
When you pass a command to ssh
, it requires quoting both from the local shell and the remote shell.
A fix for your case would be to move the first single quote slightly, to prevent the local shell from messing with the command at all. In the internal quoting, we use nested double quotes where the inner ones are backslashed.
ssh –t user@address 'su –c "echo \"user ALL=(ALL) NOPASSWD:ALL\"" >> /etc/sudoers.d/permissions’