我的目标是修改linux配置文件,并从以下位置更新其中一个设置:
PasswordAuthentication no -> PasswordAuthentication yes
我有过
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 ")我在正确的轨道上吗?
发布于 2016-07-22 03:34:38
str.replace将第一个参数作为“旧字符串”,第二个参数作为“新字符串”
str.replace(old, new[, max])你把它倒过来了。
https://stackoverflow.com/questions/38517652
复制相似问题