Harden sshd_config via python
<ol>
<li>Find line starting with "#PermitRootLogin yes" and replace with "PermitRootLogin no"</li>
<li>Append line at the bottom saying "AllowUsers user1@test.com"</li>
<li>Restart sshd daemon</li>
</ol>

<p>(My Code)</p>

<pre><code>#!/usr/bin/python3
import fileinput

for line in fileinput.input("/etc/ssh/sshd_config", inplace=True), : 
    print (line.replace("#PermitRootLogin", "PermitRootLogin no"))
</code></pre>

<p>(Error)</p>

<p>Traceback (most recent call last):
  File "./assignment4-part1.py", line 6, in 
    print (line.replace("#PermitRootLogin", "PermitRootLogin=no"))
AttributeError: 'FileInput' object has no attribute 'replace'</p>

<p>(Notes)</p>

<p>I tried different methods as seen from other posts doing find and replace line, but run into similar problems/errors.  Any guidance would be much appreciated.  I am using CentOS, and python3 is installed/updated.</p>