首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修改linux文件,并在Python中保存

问修改linux文件,并在Python中保存
EN

Stack Overflow用户
提问于 2016-07-22 03:23:42
回答 1查看 129关注 0票数 1

我的目标是修改linux配置文件,并从以下位置更新其中一个设置:

PasswordAuthentication no -> PasswordAuthentication yes

我有过

代码语言:javascript
复制
import os
import fileinput


username = raw_input("Enter username : ")
os.system("adduser -m "+username )
os.system("echo {PASSWORD-HERE} | passwd" + username)
os.system("usermod -aG sudo "+username )
os.system("chsh -s /bin/bash "+username )

with fileinput.FileInput('/etc/ssh/sshd_config', inplace=True, backup='.bak') as file:
    for line in file:
        print(line.replace('PasswordAuthentication yes', 'PasswordAuthentication no'), end='')

os.system("service ssh restart ")

我在正确的轨道上吗?

EN

回答 1

Stack Overflow用户

发布于 2016-07-22 03:34:38

str.replace将第一个参数作为“旧字符串”,第二个参数作为“新字符串”

代码语言:javascript
复制
str.replace(old, new[, max])

你把它倒过来了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38517652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档