|
import subprocess |
|
from IPython.display import clear_output |
|
|
|
def run_command(command): |
|
"""Run a shell command and handle errors.""" |
|
try: |
|
subprocess.run(command, check=True, shell=True) |
|
except subprocess.CalledProcessError as e: |
|
print(f"An error occurred: {e}") |
|
|
|
|
|
run_command("apt update") |
|
|
|
|
|
run_command("apt install openssh-server -y") |
|
run_command("apt-get install vim -y") |
|
|
|
|
|
config_client_cmd = "sudo sed -i '/PasswordAuthentication/s/^#//g' /etc/ssh/ssh_config" |
|
run_command(config_client_cmd) |
|
|
|
|
|
config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config" |
|
run_command(config_server_cmd) |
|
|
|
|
|
run_command("systemctl restart ssh") |
|
|
|
|
|
password_change_cmd = "echo 'root:qilan123' | sudo chpasswd" |
|
run_command(password_change_cmd) |
|
|
|
|
|
os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config") |
|
run_command("service ssh restart") |
|
|
|
|
|
clear_output() |
|
|