Qi28 commited on
Commit
b0d9056
·
verified ·
1 Parent(s): 19a5f9d

Update cs.py

Browse files
Files changed (1) hide show
  1. cs.py +22 -7
cs.py CHANGED
@@ -1,23 +1,38 @@
1
- #SSH
2
  import subprocess
3
  from IPython.display import clear_output
 
4
  def run_command(command):
 
5
  try:
6
  subprocess.run(command, check=True, shell=True)
7
  except subprocess.CalledProcessError as e:
8
  print(f"An error occurred: {e}")
 
 
9
  run_command("apt update")
 
 
10
  run_command("apt install openssh-server -y")
11
  run_command("apt-get install vim -y")
 
 
12
  config_client_cmd = "sudo sed -i '/PasswordAuthentication/s/^#//g' /etc/ssh/ssh_config"
13
  run_command(config_client_cmd)
 
 
14
  config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config"
15
  run_command(config_server_cmd)
 
 
16
  run_command("systemctl restart ssh")
17
- !/etc/init.d/ssh restart
18
- import os
19
- os.system("echo 'root:qilan123' | sudo chpasswd")
 
 
 
20
  os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config")
21
- os.system("service ssh restart ")
22
- os.system("export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v '/opt/conda/lib' | paste -sd ':') ")
23
- clear_output()
 
 
 
1
  import subprocess
2
  from IPython.display import clear_output
3
+
4
  def run_command(command):
5
+ """Run a shell command and handle errors."""
6
  try:
7
  subprocess.run(command, check=True, shell=True)
8
  except subprocess.CalledProcessError as e:
9
  print(f"An error occurred: {e}")
10
+
11
+ # 更新包列表
12
  run_command("apt update")
13
+
14
+ # 安装 OpenSSH 服务器和 Vim 编辑器
15
  run_command("apt install openssh-server -y")
16
  run_command("apt-get install vim -y")
17
+
18
+ # 修改 SSH 配置以允许密码认证
19
  config_client_cmd = "sudo sed -i '/PasswordAuthentication/s/^#//g' /etc/ssh/ssh_config"
20
  run_command(config_client_cmd)
21
+
22
+ # 修改 SSH 配置以允许 root 登录
23
  config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config"
24
  run_command(config_server_cmd)
25
+
26
+ # 重启 SSH 服务
27
  run_command("systemctl restart ssh")
28
+
29
+ # 设置 root 用户密码
30
+ password_change_cmd = "echo 'root:qilan123' | sudo chpasswd"
31
+ run_command(password_change_cmd)
32
+
33
+ # 确保 PermitRootLogin 设置正确并重启服务
34
  os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config")
35
+ run_command("service ssh restart")
36
+
37
+ # 清理环境变量(如果需要)
38
+ clear_output()