I need to replace existing sshd config on the remote PC and restart sshd, so I try to use this:
cat /sshd_cfg | ssh [email protected] "cat > /etc/ssh/sshd_config && service sshd restart"
but I get bash: /etc/ssh/sshd_config: Permission Denied
So to use sudo I try "echo pass | sudo -S" like that: cat /sshd_cfg | ssh [email protected] "echo pass | sudo -S cat > /etc/ssh/sshd_config && service sshd restart"
but getting the same output - Permission Denied, may be because of pipes collision? What shall I do?
Linux 190 4.3.0-2-generic #11-Ubuntu SMP Fri Dec 4 20:36:35 UTC 2015 i686 i686 i686 GNU/Linux
**
- upd
As I found, the problem is in user privileges.
If I connect directly to PC and try to execute sudo cat /dev/null > /etc/ssh/sshd_config, I get Permission Denied, but it' okay If I try sudo -H -u root bash -c 'cat /dev/null > /etc/ssh/sshd_config'.
So I tried that from remote: cat /sshd_cfg | ssh user@IP "echo password | sudo -S -H -u root bash -c 'cat > /etc/ssh/sshd_config'"
And this time no errors appeares. And the file was changed, but it became ...blank. Instead cating /sshd_cfg in it.
Why?