我的目标是修改 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 ")
我在正确的轨道上吗?
最佳答案
str.replace 会将第一个参数作为“旧字符串”,将第二个参数作为“新字符串”
str.replace(old, new[, max])
你给的是反的。
关于python - 修改一个linux文件,用Python保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38517652/