0

I had been trying to write PermitRootLogin yes in /etc/ssh/sshd_config file as a normal user.

In search of that from somewhere I got this,
echo "PermitRootLogin" yes | sudo tee -a /etc/ssh/sshd_config

Also, I got to know that "I can explicitly pass the root password for any sudo command on the same line"
Like echo <password> | sudo -S apt-get install tmux

So, my question is how can I merge these two commands and make a single command, that appends the PermitRootLogin yes to the specified file as a normal user using a root password.

pLumo
  • 26,947

1 Answers1

1

You could achieve this with a nested bash -c or sh -c command:

echo "mypassword" | sudo -S bash -c 'tee -a /etc/ssh/sshd_config <<< "PermitRootLogin yes"'

#or

echo "mypassword" | sudo -S sh -c 'echo "PermitRootLogin" yes | tee -a /etc/ssh/sshd_config'

Note, this is fairly unsafe. Consider at least adding sudo -S to HISTIGNORE (see also).

Generally better option would be to use sudoers configuration to allow some (or all) commands passwordless.


Anyways, it is generally a very bad idea to allow root login through ssh!

pLumo
  • 26,947