기본 콘텐츠로 건너뛰기

라벨이 script인 게시물 표시

expect를 이용한 조금 위험한 ssh login

보통 ssh에 암호 없이 로그인을 가능케하려면 ~/.ssh에 authorized_keys에 접속을 요청하는 쪽 키를 등록해야하지만, 서버가 수 백 대이고, 일일이 세팅하기 귀찮으면 조금 위험하지만 expect을 이용해 손쉽게 자동 로그인하게 할 수 있다. #!/usr/local/bin/expect -f set user [lrange $argv 0 0] set addr [lrange $argv 1 1] set pass [lrange $argv 2 2] set timeout -1 spawn ssh $user@$addr match_max 100000 expect {         "*?assword:*" {                 send -- $pass                 send -- "\r"                 send -- "\r"                 interact         } } 만약 바로 어떤 스크립트를 실행하고 끝내고 싶으면 스크립트를 인자에서 받아와서 ssh 명령 맨 뒤에 붙이고, interact 를 제거한 뒤에 맨 마지막 줄에 expect eof 를 삽입한다. 원본 위치: http://purewell.egloos.com/3431259

각종 편리한 BASH shell script 모음

http://bash.cyberciti.biz/ 원본 위치: http://purewell.egloos.com/3431219