第2å SSH å ¬ééµã®è¨ç½®
2008/03/25
ä»å㯠Capistrano ã使ãããã®åææ¡ä»¶ã®ä¸ã¤ã§ãã SSH ã«ã¤ãã¦ã
æ¬çªãµã¼ãã¯ç¨æããã¦ããã¨ããåæã ãããããªãã¯æ¢ã« SSH ã§æ¬çªãµã¼ãã«ãã°ã¤ã³ã§ããã¯ãã ãããããSSH ã®å ¬ééµãä½ã£ã¦æ¬çªãµã¼ãã«è¨ç½®ãã¦ããã ããããããã¾ã ãªããããããä½æ¥éå§ã ã
ãã ããWindows ãã Capistrano ã使ãããã®ã»ããã¢ããæ¹æ³ã«ã¤ãã¦ã¯ã次åï¼ç¬¬3å Windows 㧠Capistranoï¼ã§èª¬æããã
ã¾ããSSH ã®å ¬ééµãä½ãã
% ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/kuroda/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/kuroda/.ssh/id_rsa. Your public key has been saved in /home/kuroda/.ssh/id_rsa.pub. The key fingerprint is: a3:ed:8b:aa:6d:6c:92:16:70:6b:1d:51:3a:24:6f:b9 kuroda@desktop
次ã«ãå ¬ééµãæ¬çªãµã¼ãã«ã³ãã¼ãããæ¬çªãµã¼ãã®ãã¡ã¤ã³åã alpha.oiax.jp ã¨ãããã
% scp .ssh/id_rsa.pub alpha.oiax.jp:~ [email protected]'s password:
æ¬çªãµã¼ãã«ãã°ã¤ã³ããããªããä»å¾ã¯ãã¼ã«ã«ãã¹ãã§ä½æ¥ããã¨ãã®ããã³ãã㯠% ã§ããªã¢ã¼ããã¹ãï¼æ¬çªãµã¼ãï¼ã§ä½æ¥ããã¨ãã®ããã³ãã㯠$ ã§è¡¨ããã¨ã«ããã
% ssh alpha.oiax.jp Password:
æåã« app ã¦ã¼ã¶ã¼ãä½ãã
% sudo /usr/sbin/useradd -m app
ãã㯠Rails ã¢ããªã±ã¼ã·ã§ã³ããããã¤ã¡ã³ããèµ·åããããã®å°ç¨ã¦ã¼ã¶ã¼ã§ãããããããã§ã«ãã®ã¦ã¼ã¶ã¼åãä»ã®ç®çã§ä½ããã¦ããããrails ãªã©ã®å¥ã®ååãé¸ã¶ããªããéçºè å人ã®ã¢ã«ã¦ã³ãï¼ä¾ãã°ãkurodaï¼ã§ãããã¤ã¡ã³ãããæ¹æ³ãããããè¤æ°äººã§éçºãã¦ããå ´åã¯ããã¡ã¤ã«ã®ãã¼ããã·ã§ã³ã«é¢ä¿ãããããããåé¡ã«ééããããã®ã§å°ç¨ã®ã¦ã¼ã¶ã¼ãä½ããã¨ããå§ãããã
ã¾ã ~/.ssh ã«å ¬ééµãè¨ç½®ããã
$ mkdir -m 700 .ssh $ cat id_rsa.pub >> .ssh/authorized_keys
ç¶ã㦠/home/app/.ssh ã«å ¬ééµãè¨ç½®ããã
$ sudo -u app mkdir -m 700 /home/app/.ssh $ sudo -u app touch /home/app/.ssh/authorized_keys $ sudo sh -c "cat id_rsa.pub >> /home/app/.ssh/authorized_keys"
ãã°ã¢ã¦ãããã
$ exit
ãã¹ãã¬ã¼ãºãç¹°ãè¿ãå ¥åããæéãçããã人ã¯ã次ã®ããã«ã㦠ssh-agent ã«ç§å¯éµãè¨æ¶ãããã
% ssh-agent bash % ssh-add Enter passphrase for /home/kuroda/.ssh/id_rsa: Identity added: /home/kuroda/.ssh/id_rsa (/home/kuroda/.ssh/id_rsa)
å ¬ééµã§æ¬çªãµã¼ãã«ãã°ã¤ã³ããã
% ssh alpha.oiax.jp $ exit
ãã°ã¤ã³æã«ãã¹ã¯ã¼ããå°ããããªããã°ãOKã ã
次ã«ãapp ã¦ã¼ã¶ã¼ã§ãã°ã¤ã³ããã
% ssh [email protected] $ exit
ãã¡ãããã¹ã¯ã¼ãã®å ¥åãªãã§ãã°ã¤ã³ã§ããã¯ãã ã
ã§ã¯ãCapistrano ã試ãã¦ã¿ããã
ãã¼ã«ã«ãã¹ãã®é©å½ãªãã£ã¬ã¯ããªã«ã次ã®ãããªå 容ãæã¤ããã¹ããã¡ã¤ã« Capfile ãä½æãããæ¡å¼µåã¯ä»ããªããã¨ãã¾ãã'kuroda' ã®é¨åã¯ããªã¢ã¼ããã¹ãã« SSH ã§ãã°ã¤ã³ããã¦ã¼ã¶ã¼åãæå®ãã'alpha.oiax.jp' ã¯ãå®éã®ãªã¢ã¼ããã¹ãã®ååã§ç½®ãæãããã¨ã
set :user, 'kuroda' task :stamp, :hosts => "alpha.oiax.jp" do run "touch /home/kuroda/touched" end
ããã§ãalpha.oiax.jp ã«ãã°ã¤ã³ãã¦ãã³ãã³ã touch /home/kuroda/touched
ãå®è¡ããã¿ã¹ã¯ stamp ãå®ç¾©ãããã¨ã«ãªããUnix ã³ãã³ãã® touch
ã¯ããã¡ã¤ã«ã®ã¿ã¤ã ã¹ã¿ã³ããæ´æ°ãããã®ã ãããã¡ã¤ã«ããªããã°æ°è¦ã«ä½æãã¦ãããã
stamp ã¿ã¹ã¯ãå®è¡ããã«ã¯ãCapfile ãä¿åãããã£ã¬ã¯ããªã«ç§»åãã¦ãcap stamp
ã¨å
¥åããã
% cap stamp * executing `stamp' * executing "touch /home/kuroda/touched" servers: ["alpha.oiax.jp"] [alpha.oiax.jp] executing command command finished
æ¬çªãµã¼ãã§çµæã確èªããã
$ pwd /home/kuroda $ la -l touched -rw-r--r-- 1 kuroda kuroda 5 Mar 24 22:58 touched
stamp ã¿ã¹ã¯ãå®è¡ããã¾ã§ã¯åå¨ããªãã£ã touched ãã¡ã¤ã«ãçæãããã
[æ¹è¨] 2008/05/17 ã¦ã¼ã¶ã¼ app ã§ãªã¢ã¼ããã¹ãã«ãã°ã¤ã³ããæ¹å¼ã«åããã¦è¨è¿°ãä¿®æ£ã