3

I'm trying to figure out how to enable PermitRootLogin with OSX sed.

I know about the OSX sed issue where you have to give an empty string at the start.

I just need the regex I actually need to do:

if #PermitRootLogin yes or #PermitRootLogin no then replace with PermitRootLogin yes

I've got:

sudo sed -i '' 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/sshd_config

But this doesn't include if ##PermitRootLogin yes

Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
Peter Souter
  • 5,110
  • 1
  • 33
  • 62

1 Answers1

4

The version of sed in OS X requires a parameter after -i for the backup file suffix.

If you don't want a backup file, you have to provide an explicit empty string:

sed -i '' 's/^#?PermitRootLogin \(no\|yes\)/PermitRootLogin yes/' /etc/sshd_config

Without this argument, it's taking the s/.../.../ command as the suffix, and /etc/sshd_config as sed editing command.

Note that some time between Snow Leopard and El Capitan, the location of this SSH configuration file moved from /etc/sshd_config to /etc/ssh/ssh_config.

Barmar
  • 741,623
  • 53
  • 500
  • 612