** 環境 [#md6d2dcd] - OS X 10.11 El Capitan - Vagrant 1.8.1 - VirtualBox 5.0.20 r106931 - CentOS 7.2.1511 ** サーバー側設定 [#oc98c04e] - シェルスクリプト作成(hello.sh) $ vim hello.sh #!/bin/bash echo "Hello World!" exit 0 $ chmod +x hello.sh $ ./hello.sh Hello World! ** クライアント(Mac)側設定 [#t4e2c8df] - Homebrewのインストール $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" $ source ~/.bash_profile $ brew -v Homebrew 0.9.9 (git revision 9a9a; last commit 2016-05-04) Homebrew/homebrew-core (no git repository) - sshpassインストール $ brew install http://git.io/sshpass.rb $ which sshpass /usr/local/bin/shapes - シェル起動用Pythonスクリプト作成(hello_shell.py) # coding: UTF-8 import subprocess SSH_USER = "User Name" SSH_PASS = "Password" SSH_HOST = "192.168.33.10" CMD = "./hello.sh" subprocess.call(["sshpass", "-p", SSH_PASS, "ssh", SSH_USER + "@" + SSH_HOST, CMD]) ** 実行 [#kbaff4e1] - クライアントの "hello_shell.py" を実行(サーバーへSSHログイン後 "hello.sh" を実行) - クライアント上の "hello_shell.py" を実行(サーバーへSSH自動ログイン後 "hello.sh" を実行) $ python hello_shell.py Hello World!