Linux.Script.如何修改已被调用的只读文件内容

来源:互联网 发布:软件测试经验 编辑:程序博客网 时间:2024/05/16 17:12

<背景>

[root@CLA-0(**) /etc/ssh]                                              
# ls -l sshd*                                                                  
-rw-r--r-- 1 root root 1439 Apr  1  2010 sshd_config                           
-r--r--r-- 1 root root 1403 Jan  2 02:46 sshd_external_config                  
-r--r--r-- 1 root root 1374 Jan  1 03:11 sshd_internal_config

 

需要修改字符串使ssh服务支持root用户远程登录。

 

<解决方法>

chmod 644 sshd_internal_config sshd_external_config
vi -e -s -c ":%s/PermitRootLogin without-password/PermitRootLogin yes/g" -c "wq" /etc/ssh/sshd_config
vi -e -s -c ":%s/PermitRootLogin no/PermitRootLogin yes/g" -c "wq" /etc/ssh/sshd_external_config
vi -e -s -c ":%s/PermitRootLogin without-password/PermitRootLogin yes/g" -c "wq" /etc/ssh/sshd_internal_config
chmod 444 sshd_internal_config sshd_external_config
fshascli -rn /ssh

 

<解释>

vi  -e(进入命令模式) -s(命令模式下,进入silent模式) -c<comand>(执行命令)

:%s/PermitRootLogin without-password/PermitRootLogin yes/g

:[address]s/xxx/ooo[/option]       %(整个缓冲区) s//(查找并替换字符串) /g(全局替换)

"wq"(i 不被支持,所以先修改权限)

 

<补充>

[address]支持加减号

:/uer/+2s/8192/10/      在第一个包含字母串uer的行起,+2行,将8192修改为10.

-s silent mode 静默执行,不输出打印消息

 

原创粉丝点击