我想使用bash脚本编辑sshd_config文件。然而,我一直收到一个错误。如果能得到任何帮助,我将不胜感激。
这是我的脚本:
if ! grep "IgnoreRhosts" "/etc/ssh/sshd_config"; then
sed -i /etc/ssh/sshd_config -e '/# Don't read the user's ~/.rhosts and ~/.shosts files/a IgnoreRhosts yes'
printf "\e[32m IGNORERHOSTS YES ADDED\e[0m\n"
elif grep "#IgnoreRhosts yes" "/etc/ssh/sshd_config"; then
sed -i 's/^#IgnoreRhosts yes/IgnoreRhosts yes/' /etc/ssh/sshd_config
printf "\e[32mSUCCESSFULLY CHANGED\e[0m\n"
else
printf "\e[32mNO CHANGES NEEDED\e[0m\n"
fi
这是我得到的错误:
sed: -e expression #1, char 7: unterminated address regex
脚本错误行:
sed -i /etc/ssh/sshd_config -e '/# Don't read the user's ~/.rhosts and ~/.shosts files/a IgnoreRhosts yes'
发布于 2017-07-24 17:19:15
这个应该行得通:
sed -i /etc/ssh/sshd_config -e "\|# Don't read the user's ~/.rhosts and ~/.shosts files|a IgnoreRhosts yes"
说明:在此脚本中,我使用|
作为分隔符,以使其更具可读性。该分隔符由first \
(more info here)定义
然后,我使用双引号而不是单引号,以避免在单词Don't
和user's
中转义撇号
https://stackoverflow.com/questions/45275947
复制相似问题