Update server.py
Browse files
server.py
CHANGED
|
@@ -98,6 +98,11 @@ def Oneapi():
|
|
| 98 |
# Oneapi()
|
| 99 |
|
| 100 |
# SSH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def ssh():
|
| 102 |
print('-----------SSH开始-------------')
|
| 103 |
subprocess.run("apt update", check=True, shell=True)
|
|
@@ -108,7 +113,7 @@ def ssh():
|
|
| 108 |
subprocess.run(config_client_cmd, check=True, shell=True)
|
| 109 |
config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config"
|
| 110 |
subprocess.run(config_server_cmd, check=True, shell=True)
|
| 111 |
-
|
| 112 |
|
| 113 |
os.system("/etc/init.d/ssh restart")
|
| 114 |
os.system("echo 'root:qilan' | sudo chpasswd")
|
|
|
|
| 98 |
# Oneapi()
|
| 99 |
|
| 100 |
# SSH
|
| 101 |
+
def run_command(command):
|
| 102 |
+
try:
|
| 103 |
+
subprocess.run(command, check=True, shell=True)
|
| 104 |
+
except subprocess.CalledProcessError as e:
|
| 105 |
+
print(f"An error occurred: {e}")
|
| 106 |
def ssh():
|
| 107 |
print('-----------SSH开始-------------')
|
| 108 |
subprocess.run("apt update", check=True, shell=True)
|
|
|
|
| 113 |
subprocess.run(config_client_cmd, check=True, shell=True)
|
| 114 |
config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config"
|
| 115 |
subprocess.run(config_server_cmd, check=True, shell=True)
|
| 116 |
+
run_command("systemctl restart ssh")
|
| 117 |
|
| 118 |
os.system("/etc/init.d/ssh restart")
|
| 119 |
os.system("echo 'root:qilan' | sudo chpasswd")
|