2016-07-22 165 views
1

我的目標是修改Linux的配置文件,從更新的設置之一:修改Linux文件,並在Python保存

的PasswordAuthentication no - > Password驗證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 ") 

上午我在正確的軌道?

回答

0

str.replace將第一個參數爲「老串」和第二個「新字符串」

str.replace(old, new[, max]) 

您在反向給了它。

相關問題