首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hetzner hcloud Python使用SSH密钥创建服务器

Hetzner hcloud Python使用SSH密钥创建服务器
EN

Stack Overflow用户
提问于 2019-04-27 21:43:04
回答 1查看 212关注 0票数 2

我想创建一个带有Hetzner hcloud Python库的服务器。https://github.com/hetznercloud/hcloud-python

如何注入SSH密钥?我已经创建了一个名为" SSH-Key“的SSH-Key。

代码语言:javascript
复制
from hcloud import Client
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType

client = Client(token="I7................I")  # Please paste your API token here between the quotes
response = client.servers.create(name="my-server", server_type=ServerType("cx11"), image=Image(name="ubuntu-18.04"), ssh_keys=ssh_keys(name=(["SSH-Key"])))
server = response.server
print(server)

我找不到一个很好的例子来使用SSH-Keys来完成这项工作。

EN

回答 1

Stack Overflow用户

发布于 2021-01-31 01:51:50

你需要传递一个ssh密钥列表,即。client.ssh_keys.get_list()

2021-01-30的完整工作示例:

代码语言:javascript
复制
    from hcloud import Client
    from hcloud.images.domain import Image
    from hcloud.locations.domain import Location
    from hcloud.server_types.domain import ServerType
    
    
    client = Client("your_api_key_here")
    ssh = client.ssh_keys.get_by_name("ssh_key_name_set_on_hetzner")
    
    response = client.servers.create(
        name="example-server-name",
        location=Location(name="nbg1"),
        server_type=ServerType("cx11"),
        image=Image(name="debian-10"),
        ssh_keys=[ssh],
    )
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55881159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档