Files
mkdocs/cloude连接腾讯云服务器.txt
2026-06-27 19:10:58 +08:00

22 lines
1.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
101.43.95.130 username:renjianbo port 22 密码123456
● 经历了以下步骤:
1. 直接用 ssh 命令 — 失败,因为缺少 sshpass 无法在命令行传入密码
2. 检测到 Python 3.12 — WindowsApps 里的 python3 不可用,用了实际安装的 C:\Users\Administrator\AppData\Local\Programs\Python\Python312\python
3. 安装 paramiko — pip install paramiko,Python 的 SSH 库 4. 用 paramiko 连接 — 脚本如下:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 自动接受主机密钥
ssh.connect('101.43.95.130', port=22, username='renjianbo', password='123456', timeout=10)
# 连接成功后执行命令
stdin, stdout, stderr = ssh.exec_command('hostname && uname -a && uptime')
print(stdout.read().decode())
ssh.close()
关键点:paramiko 支持直接在代码里传入密码,绕过了 OpenSSH 客户端不支持命令行传密码的限制。