188金宝搏官网,企业场景运维案例:sed实战修改多行配置技巧
金宝搏平台,本博文出自Bkjia博客老男孩linux运维,有任何问题请进入博主页面互动讨论!
博文地址:
老男孩老师有关sed实战技巧分享,来自课堂教学内容实战
1、在指定行前插入两行内容,分别为oldboy和oldgirl。
提示:被修改的文件内容必须要大于等于2行
sed -i '2 ioldboynoldgirl' sshd_config
2、企业实战例子:快速更改SSH配置(一键完成增加若干参数)
增加:
[[email protected] ssh]# sed -i '13 iPort 52113nPermitRootLogin nonPermitEmptyPasswords nonUseDNS nonGSSAPIAuthentication no' sshd_config
查看:
[[email protected] ssh]# sed -n '13,17p' sshd_config Port 52113 PermitRootLogin no PermitEmptyPasswords no UseDNS no GSSAPIAuthentication no
3、如果是快速修改参数可以用如下方法(企业实战例子)
echo "#--------sshConfig修改ssh默认登录端口,禁止root登录----------------------------#" cp /etc/ssh/sshd_config /etc/ssh/sshd_config.$(date +"%F"-$RANDOM) sed -i 's%#Port 22%Port 52113%' /etc/ssh/sshd_config sed -i 's%#PermitRootLogin yes%PermitRootLogin no%' /etc/ssh/sshd_config sed -i 's%#PermitEmptyPasswords no%PermitEmptyPasswords no%' /etc/ssh/sshd_config sed -i 's%#UseDNS yes%UseDNS no%' /etc/ssh/sshd_config sed -i 's%GSSAPIAuthentication yes%GSSAPIAuthentication no%' /etc/ssh/sshd_config egrep "UseDNS|52113|RootLogin|EmptyPass|GSSAPIAuthentication" /etc/ssh/sshd_config
提示:如果是指定行修改还可以是:
sed -i '2735s/admin_tenant_name=service/adminadmin_tenant_name=admin/' nova.conf
本博文出自Bkjia博客老男孩linux运维,有任何问题请进入博主页面互动讨论!
博文地址:http:…