# SED
Stream EDitor tricks
# Replacing lines
Used for changing configuration options that exist on a single line
# Example of disabling root login with passwords via SSH
sed -i "s/.*PermitRootLogin.*/PermitRootLogin prohibit-password/g" /etc/ssh/sshd_config
sed -i "s/.*PasswordAuthentication.*/PasswordAuthentication no/g" /etc/ssh/sshd_config
The -i
option means in-line editing of the specified file (/etc/ssh/sshd_config
)
The s
at the start of the line is a regexp search+replace
s/<regexp>/<replacement>/
# (Un)comment lines
# Commenting
sed -i "/needle/s/^/#/g" /path/to/haystack
# Uncommenting
sed -i "/^#needle/s/^#*//g" /path/to/haystack