0

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.

zetter
  • 3

1 Answers1

4

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.
A.B.
  • 3,442