AWS 中的 SSH 身份验证问题

AWS 中的 SSH 身份验证问题

我在远程 Ubuntu 服务器中运行 docker Yang Development Kit for python ydk-py。我想使用远程服务器和运行 CSR 1000v(SSH 身份验证)的 AWS EC2 实例建立连接

以前,我使用以下 ssh 命令访问我的路由器:

ssh -i "ssh-key.pem" [email protected] 其中 ec2-xx-xx-xx-xxx.us-west-2.compute.amazonaws.com是主机名,ec2-user是用户名,ssh 密钥ssh-key.pem用于身份验证。

作为第一步,我想在这里运行给定的示例ydk-py 样本

这是给定示例中创建 NETCONF 会话的 Python 代码:

    provider = NetconfServiceProvider(address="10.0.0.1",
                                      port=830,
                                      username="admin",
                                      password="admin",
                                      protocol="ssh")

我试过

provider = NetconfServiceProvider(address="ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com", 
username= "ec2-user", 
 public_key_path="mykey.pem")

我遇到了这个错误

Traceback (most recent call last):
  File "hello-ydk.py", line 18, in <module>
    private_key_path="mykey.pem")
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. ydk_.providers.NetconfServiceProvider(repo: ydk_.path.Repository, address: unicode, username: unicode, password: unicode, port: int=830L, protocol: unicode=u'ssh', on_demand: bool=True, timeout: int=-1L)
    2. ydk_.providers.NetconfServiceProvider(address: unicode, username: unicode, password: unicode, port: int=830L, protocol: unicode=u'ssh', on_demand: bool=True, common_cache: bool=False, timeout: int=-1L)
    3. ydk_.providers.NetconfServiceProvider(repo: ydk_.path.Repository, address: unicode, username: unicode, private_key_path: unicode, public_key_path: unicode, port: int=830L, on_demand: bool=True, timeout: int=-1L)
    4. ydk_.providers.NetconfServiceProvider(address: unicode, username: unicode, private_key_path: unicode, public_key_path: unicode, port: int=830L, on_demand: bool=True, common_cache: bool=False, timeout: int=-1L)

Invoked with: 'ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com', 'ec2-user'; kwargs: repo=None, public_key_path='mykey.pem'

我尝试调试 python 脚本,结果发现参数类型 private_key_path 有问题。

-> username="ec2-user",
(Pdb) next
> /home/server/shared_files/hello-ydk.py(15)<module>()
-> private_key_path="/home/server/shared_files/mykey.pem")
(Pdb) next
TypeError: "__init__(): incompatible constructor arguments. The following argument types are supported:\n    .../home/server/shared_files/mykey.pem', address='ec2-35-166-239-202.us-west-2.compute.amazonaws.com'"

我该如何解决这个问题?

答案1

在定义时,似乎ydk要求您提供私钥和公钥NetconfServiceProvider

 4. ydk_.providers.NetconfServiceProvider(address: unicode, username: unicode, private_key_path: unicode, public_key_path: unicode, port: int=830L, on_demand: bool=True, common_cache: bool=False, timeout: int=-1L)

因此您需要使用:

provider = NetconfServiceProvider(address="ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com", 
  username= "ec2-user", 
  private_key_path="mykey.pem", 
  public_key_path="mykey.pub")

相关内容