SecurityAmoeba SecurityAmoeba - 4 months ago 20
Linux Question

Config modifcation with sed

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:

PermitRootLogin without-password


Here is my code:

sed 's/^\(PermitRootLogin\s*.\s*\).*$/\1Yes/' sshd_config


So the goal is to replace the 'without-password' with yes. It appears to work except I receive this instead:

PermitRootLogin wYes


Thoughts? Thanks in advance

Answer

Try this:

sed 's/^\(PermitRootLogin \).*/\1Yes/' sshd_config

Use the -i option to edit the file in place:

sed -i 's/^\(PermitRootLogin \).*/\1Yes/' sshd_config

Your pattern was capturing w because it's the first character (.) after zero or more space (\s*) in regex \s*.

Comments