如何通过Python连接到VPS?

问题描述 投票:0回答:1

我想编写一个获取服务器列表(VPS)并检查服务器是否可用以及用户名和密码正确的程序。所以我用谷歌搜索,没有关于通过python连接到VPS的任何信息。可能吗??如果是怎么回事?谢谢

python vps rdp
1个回答
0
投票

我假设您想通过SSH进入VPS。为此,您必须在Python中找到一个模块,该模块可用于建立SSH连接。我建议使用Paramiko。这是一个有关如何连接服务器的快速示例:

import paramiko
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('ssh.example.com')
stdin, stdout, stderr = client.exec_command('ls -l')

或者如果您想使用用户名和密码代替:

import paramiko
client = paramiko.SSHClient()
client.connect('ssh.example.com', username='root', password='toor')
stdin, stdout, stderr = client.exec_command('ls -l')
© www.soinside.com 2019 - 2024. All rights reserved.