import paramiko
#edit the following line please
username, hostname = "YOUR_USERNAME@EXTERNAL_IP_ADDRESS".split("@")
client = paramiko.SSHClient()
#edit the following line also, with the path to the private ssh key (correspondent to the public one you've registered with your GCE instance)
key_filename=""
#on cloud shell would be something like /home/YOUR_USERNAME/.ssh/google_compute_engine
c = client.connect(username=username, hostname=hostname, key_filename=key_filename)
stdin, stdout, stderr = client.exec_command("cat /etc/os-release") #assuming is linux
print(stdout.read().decode())
client.close()
我将使用paramiko,一个Python第三方库。在
但首先在GCP端做一些简单的设置,只需粘贴您想要连接的机器的公共ssh密钥,这是documentation,并获取您想要连接的Google计算引擎(GCE)实例的外部IP地址。在
然后:
相关问题 更多 >
编程相关推荐