I want to modify /etc/hosts (and later also hostname) via a script and ssh. So I'm logged in via ssh and this works:
sudo nano /etc/hosts
It shows the remote hosts file in nano. However I was trying this (via commandline, but this should work in order to make it work in a script right?):
echo [mypassword] | sudo -S nano /etc/hosts
but get this output:
Recieved SIGHUP or SIGTERM
Buffer written to /etc/hosts.save
I just saw that this also happens with more simple text-files (e.g. test.txt). Any ideas how to fix this?
And yes, I am aware of the insecurity of the clear password. :)
Thanks in advance