シェルスクリプトでパスワードを使用したSSH接続の作成

シェルスクリプトでパスワードを使用したSSH接続の作成

ユーザー名とパスワードを使用してクライアントにログインできます。 SSHキーがよりよく安全であることを知っていますが、今でもこれを行うためにパスワードを使用したいと思います。

[michael@devserver ~]$ ssh -p 3333  -D 3333 testuser@localhost
testuser@localhost's password:
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 3333
Could not request local forwarding.

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Nov 16 17:46:54 2017 from localhost
testuser@mypi:~ $

私は同じことをしたいのですが、台本にしたいです。私の試みは次のとおりです。ただし、試してもパスワードを入力するように求められます。また、後でコメントアウトされた行に示すように、SSHキーを使用してこれを試みます。

#!/bin/sh
userServer='serveruser'
userClient='clientuser'
passwordServer='serverpassword'
passwordClient='clientpassword'
passwordClient=3333

if echo $passwordClient | ssh -p $port $userClient@localhost | grep ECDSA;  then
# or if keys are used:
# if su -c "ssh -p $port $userClient@localhost" $userServer | grep ECDSA;  then
        echo 'Logon successful'
else
        echo 'Connection refused'
fi

ベストアンサー1

おすすめ記事