0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

sshtunnelが使えなくなった

Posted at

sshtunnel 0.4.0が使えなくなった。

paramikoを4.0.0にしたら

AttributeError: module 'paramiko' has no attribute 'DSSKey'

こんなことになった。

とりあえずparamikoを3.5.1に戻してsshtunnelの更新を待っている状態。
でもsshtunnelはgit見ていてもなかなか更新してくれそうもないうえに、やりたいことはコマンド実行だけなので仕方なく簡易トンネルを開通させました。
例外拾ったり、パスワード/パスフレーズ/鍵などは必要に応じて適宜追加。

以下のコードはparamiko 4.0.0では試していません。

#!/usr/bin/env python

import paramiko

# 踏み台
bastion_server = "192.0.2.1"
bastion_port = 50000
bastion_user = "hoge"

# 実施対象
target_server = "198.51.100.99"
target_port = 22
target_user = "piyo"

# 踏み台へ接続
bastion = paramiko.SSHClient()
bastion.set_missing_host_key_policy(paramiko.AutoAddPolicy)
bastion.connect(hostname=bastion_server, username=bastion_user)

# 実施対象への接続準備
target_transport = bastion.get_transport()
target_channel = target_transport.open_channel(
    kind="direct-tcpip",
    dest_addr=(target_server, target_port),
    src_addr=(bastion_server, bastion_port),
)

# 実施対象への接続
target = paramiko.SSHClient()
target.set_missing_host_key_policy(paramiko.AutoAddPolicy)
target.connect(hostname=target_server, username=target_user, sock=target_ch)

# コマンド実行&表示
_, stdout, _ = target.exec_command("実施したいコマンド")
for line in [x.rstrip("\r\n") for x in stdout]:
    print(line)

# 後始末
target.close()
bastion.close()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?