That's a great question! sed stands for Stream Editor. It is a very powerful tool used to parse and transform text in a file or from a command's output.
In the command you are about to run:
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
Here is the breakdown of how it modifies the file:
1. The -i flag (In-place)
By default, sed just prints the modified text to your screen and doesn't change the actual file. The -i flag tells sed to edit the file "in-place", meaning it saves the changes directly back into /etc/ssh/sshd_config.
2. The s command (Substitute)
The s at the beginning of the expression stands for substitute. It follows a specific format:
's/find_this/replace_with_this/'
PasswordAuthentication no: This is the patternsedsearches for in the file.PasswordAuthentication yes: This is whatsedwill put in its place once it finds a match.
3. How it processes the file
sedreads the file line by line.- It looks at a line and checks: "Does this line contain 'PasswordAuthentication no'?"
- If no, it moves to the next line.
- If yes, it replaces that specific text with 'PasswordAuthentication yes'.
- Because of the
-iflag, it writes these changes back to the disk.
Why use sed instead of a text editor?
In Linux administration and cybersecurity, sed is preferred for these tasks because:
- Speed: It’s much faster than opening a file in
nanoorvim, searching for a line, and typing. - Automation: You can put this command in a script to configure 1,000 servers instantly!
Pro Tip: If you ever want to be safe, you can use sed -i.bak .... This will create a backup of the original file (named sshd_config.bak) before making the changes!
Give the command a try now, and then you can restart the SSH service to apply the update