LoginSignup
0
0

More than 3 years have passed since last update.

SSHパスワード認証時の入力を自動化する

Posted at

SSH公開鍵認証だとsshconfigに記載すればいいが、パスワード認証の場合はセキュリティの関係でパスワードを記載することは許可されていない。
そのため、自動化するためにはsshpassというツールを使ってワンコマンドで作成する必要があった。

sshpassをインストールする

brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

** インストールされているかを確認する **

sshpass
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
   -f filename   Take password to use from file
   -d number     Use number as file descriptor for getting password
   -p password   Provide password as argument (security unwise)
   -e            Password is passed as env-var "SSHPASS"
   With no parameters - password will be taken from stdin

   -P prompt     Which string should sshpass search for to detect a password prompt
   -v            Be verbose about what you're doing
   -h            Show help (this screen)
   -V            Print version information
At most one of -f, -d, -p or -e should be used

sshpassを使ってログインできるか試す

sshpass -p "パスワード" ssh ユーザ名@ホスト名

コマンドを登録する
毎回入力するのは手間なので、自分の使っているシェルファイルに関数として登録しよう。
他に書くところがあるのかもしれないが、ひとまず.zprofileに記載した。


function myssh(){ 
  sshpass -p "パスワード" ssh ユーザ名@ホスト名
}

sourceで読み込み直して、コマンドが実行できるかを確認しておしまい。


myssh
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