LoginSignup
7
7

More than 5 years have passed since last update.

ログインしないでSSH接続できるかをまとめて確認する

Last updated at Posted at 2015-11-10

know_hosts にないホストの接続は yes/no確認が出でるので .ssh/config に以下を記述する。※ echo yes | もありっちゃありだが。

Host *
    StrictHostKeyChecking no

以下をファイルに保存して実行。
- .ssh/configで指定したホスト名なら username@ の指定は不要。
- エラーメッセージも出したければ -qオプションをはずす。

# ホストの一覧
check_hosts=(
    server1
    server2
    server3
    server4
    ...
)

for host in ${check_hosts[*]}
do
    ssh -q username@${host} -- :;
    if [ $? = 0 ]; then
        echo -e "\033[36m$host: ssh connection OK\033[0m"
    else
        echo -e "\033[31m$host: ssh connection denied\033[0m"
    fi
done
7
7
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
7
7