发布时间:2019-08-31 09:40:46编辑:auto阅读(1766)
#!/usr/bin/env python # coding:utf8 import tempfile import os import sys import re file = tempfile.TemporaryFile() oldFile = 'sshd_config' if os.path.exists(oldFile): openOldFile = open(oldFile, 'r') else: print "file %s not found" % oldFile sys.exit() for line in openOldFile: line = re.sub(r'^#(PubkeyAuthentication)', '\g<1>', line, flags=re.M) line = re.sub(r'^#(AuthorizedKeysFile)', '\g<1>', line, flags=re.M) line = re.sub(r'(^PasswordAuthentication) yes', '\g<1> no', line, flags=re.M) file.write(line) openOldFile.close() file.seek(0) tmpFile = file.read() if os.path.exists(oldFile): os.remove(oldFile) writeFile = open(oldFile, 'w') writeFile.write(tmpFile) file.close()
上一篇: Python 初探
下一篇: python操作mysql
47881
46450
37333
34773
29347
26008
24961
19979
19582
18075
5821°
6449°
5962°
5988°
7093°
5937°
5981°
6472°
6437°
7818°