Sorry this is a quick one. I am attempting to modify the value of an ssh config file using a simple sed command (as part of a larger script performing a number of functions). I can't seem to figure out why it is not working. Here is the line of the config I am trying to change:
sed 's/^\(PermitRootLogin\s*.\s*\).*$/\1Yes/' sshd_config
Let's break down the regexp:
^matches the beginning of the line
\(starts a capture grou
PermitRootLoginmatches that directive
\s*matches the longest sequence of spaces after the directive
.matches the first character after the spaces, which is the
wat the beginning of
\s*matches the longest sequence of spaces after the
w. Since there are no spaces there, it matches the empty string.
\)ends the capture group
All the above gets put into capture group
.*matches everything after that.
$matches the end of the line.
So capture group
PermitRootLogin w. You then copy that into the replacement, with
Yes added to it. The result is
I would just use
sed 's/^PermitRootLogin\s.*$/PermitRootLogin Yes/' sshd_config
There's no need for a capture group when you don't need to copy any variable match to the replacement.