0

This question already has an answer here:

I am writing a script to modify settings on my Ubuntu server.

I have the following line in it:

sudo sed 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config

The problem is that the change will not remain. It simply changes the 'no' back to 'yes'.

When the command executes, the modified file immediately displays in the terminal showing the 'no', but when I cat the file or open it in vim it shows a 'yes' again.

Additionaly, I can open sshd_config in vim and modify it manually and the change remains just fine.

Any thoughts?

Thanks.

marked as duplicate by G-Man, Matteo, Stephen Kitt, Michael Homer, Archemar Sep 1 '15 at 8:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Simply start the command with the -i switch

sudo sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config

From man sed

-i[SUFFIX], --in-place[=SUFFIX]
    edit files in place (makes backup if extension supplied).
    The default operation mode is to break symbolic and hard links.
    This can be changed with --follow-symlinks and --copy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.