パスワードを入力せずにSSHを構成する

パスワードを入力せずにSSHを構成する

ここでの目標は、ssh 10.0.200.9.switch -l customer私のラップトップにのみ書いて、パスワードを入力せずにログインできるようにすることです。

  • スイッチはローカルLAN内にありますLaptop --> bastion.example.com --> 10.0.200.9
  • スイッチはSSHキーをサポートせず、パスワードのみをサポートします。
  • 私のラップトップとフォートサーバーの両方がOpenSSH 7.2p2を実行しています。
  • パスワードプロンプトをスキップしようとしているときにsshpass 1.05を使用しています。他の解決策がある場合、私は開いています。

これは半分しか機能しません。

/home/user/.ssh/config configuration 1

Host bastion
    hostname bastion.example.com
    port 2222
    user root
    identityfile /home/user/.ssh/id_rsa

Match host *.switch user customer
    ProxyCommand ssh bastion -W $(echo %h | grep -Po '^[0-9.]+[0-9]+' ):%p

うまく動作しますが、パスワードが必要です

user@laptop:~/.ssh$ ssh 10.0.200.9.switch -l customer
[email protected]'s password: 

Type 'help' or '?' to get help.
Switch# 

動作し、パスワードを要求しませんが、コンソールに書き込むのに時間がかかります。

user@laptop:~/.ssh$ export SSHPASS=secretPassWord
user@laptop:~/.ssh$ sshpass -e ssh 10.0.200.9.switch -l customer

Type 'help' or '?' to get help.
Switch

これはうまくいきません:

/home/user/.ssh/config configuration 2

Host bastion
    hostname bastion.example.com
    port 2222
    user root
    identityfile /home/user/.ssh/id_rsa

Match host *.switch user customer
    ProxyCommand sshpass -e ssh bastion -W $(echo %h | grep -Po '^[0-9.]+[0-9]+' ):%p

変更は.ssh/config file影響しません。

user@laptop:~/.ssh$ export SSHPASS=secretPassWord
user@laptop:~/.ssh$ ssh 10.0.200.9.switch -l customer
[email protected]'s password: 

ベストアンサー1

あなたの設定では、ProxyCommandはスイッチへの最終接続のためのパスワードではなく、接続されるsshpassSSH接続のためのパスワードを提供しようとしています。bastionバンドルsshpass 外部外部sshProxyCommandが動作しているようです。

laptop$ export SSHPASS=sshhhh    
laptop$ sshpass -e ssh -o'Proxycommand ssh customer@bastion -W final.target.switch:22' blah@blah

sshpassこれは、SSHクライアントが自分のパスワードを受け入れるように欺くために別のttyに配置されるため、sshpassSSHクライアントの前に実行する必要があるようです。そのため、脱出が機能しない可能性がありsshます。sshpassssh/config

ただし、必要なオプションsshpassでスクリプトを実行することは可能です。sshこれはあなたがしたように必要な設定を設定することで私にとって効果的でした~/.ssh/config

#/bin/bash
if [ -z "$1" ] ; then echo "usage: $0 <args...>" ; exit 1 ; fi
sshpass -e ssh "$@"

ユーザーがログインするように設定すること.ssh/configもできますので、必要ありません。また、不明なホストキーに対する要求を-lうまく処理できないようです。sshpasssshknown_hostsStrictHostKeyChecking no

おすすめ記事