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 ")
上午我在正確的軌道?