Modify a linux file, and save in Python -


my goal modify linux config file , update 1 of settings :

passwordauthentication no --> passwordauthentication yes


i have

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 )  fileinput.fileinput('/etc/ssh/sshd_config', inplace=true, backup='.bak') file:     line in file:         print(line.replace('passwordauthentication yes', 'passwordauthentication no'), end='')  os.system("service ssh restart ") 

am on right track ?

str.replace take first argument "old string" , second 1 "new string"

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

you have given in reverse.


Comments