Linuxã§ãã¼ã«ã«ãã¹ãã¨ãªã¢ã¼ããã¹ãéã§ãã¡ã¤ã«ã転éããå ´åã¯ãscpã³ãã³ãã使ãã¾ããscpã³ãã³ãã¯SSHãããã³ã«ã使ç¨ãã¾ãããã®ããããããã¯ã¼ã¯éä¿¡ã¯æå·åãããã®ã§ãå®å ¨ã«ãã¡ã¤ã«ã®è»¢éãè¡ããã¨ãã§ãã¾ãã
scpã³ãã³ãã®ä½¿ãæ¹
scpã³ãã³ãã®æ§æã¯ä»¥ä¸ã®éãã§ãã
1 |
$ scp [ãªãã·ã§ã³] ã³ãã¼å
ã³ãã¼å
|
主ãªãªãã·ã§ã³
-C | éä¿¡ãå§ç¸®ãã |
-i ç§å¯éµãã¡ã¤ã« | RSAã¾ãã¯DSAèªè¨¼ã®ç§å¯éµãã¡ã¤ã«ãæå®ãã |
-P ãã¼ãçªå· | ãã¼ãçªå·ãæå®ãã |
-p | ãªãªã¸ãã«ãã¡ã¤ã«ã®æ´æ°æéã¨ã¢ã¼ããç¶æãã |
-r | ãã£ã¬ã¯ããªå ãå帰çã«ã³ãã¼ãã |
-v | ããã°ã¬ã¹æ å ±ã表示ãã |
-1 | SSH1ã使ç¨ãã |
-2 | SSH2ã使ç¨ãã |
-4 | IPv4ã使ç¨ãã |
-6 | IPv6ã使ç¨ãã |
ãªã¢ã¼ããã¹ããããã¼ã«ã«ã«ãã¡ã¤ã«ãã³ãã¼ãã
ãªã¢ã¼ããã¹ããããã¼ã«ã«ã®ã~/tmpãã«ã³ãã¼ããä¾ãï¼ã¤ç¤ºãã¾ãã
1 2 3 4 5 6 7 8 |
# ã²ã¨ã¤ã®ãã¡ã¤ã«ã/home/user/file1ããã³ãã¼ããä¾ $ scp user@192.168.10.1:/home/user/file1 ~/tmp # ã¯ã¤ã«ãã«ã¼ãã§è¤æ°ã®ãã¡ã¤ã«ãã³ãã¼ããä¾ $ scp user@192.168.10.1:/home/user/*.txt ~/tmp # è¤æ°ã®ãã¡ã¤ã«ãã{}ã§å²ãã§ã,ãã§åºåãæå®ãã³ãã¼ããä¾ $ scp user@192.168.10.1:/home/user/{file1,file2,file3} ~/tmp |
scpã³ãã³ãã§ã¯ã@ãã®åã«ãªã¢ã¼ããã¹ãã«æ¥ç¶ããã¦ã¼ã¶ã¼åãæå®ãã¾ããã¾ãããï¼ ãã®å¾ã«ããã¹ãåãã¾ãã¯ãIPã¢ãã¬ã¹ããæå®ãããï¼ãã®å¾ã«ãã¡ã¤ã«ãã¹ãæå®ãã¾ãã
ãã¼ã«ã«ãããªã¢ã¼ããã¹ãã«ãã¡ã¤ã«ãã³ãã¼ãã
ãã¼ã«ã«ã®ã~/tmp/file1ãããªã¢ã¼ããã¹ãã®ã/home/user/tmp/ãã«ã³ãã¼ããä¾ã§ãã
1 2 3 |
# scp ã³ãã¼å
ãã¡ã¤ã« ã¦ã¼ã¶å@ãªã¢ã¼ãã»ãã¹ãå:/ãªã¢ã¼ãå
ã®PATH $ scp ~/tmp/file1 user@192.168.10.1:/home/user/tmp/ |
ãªã¢ã¼ããã¹ãããå¥ã®ãªã¢ã¼ããã¹ãã«ãã¡ã¤ã«ãã³ãã¼ãã
ãªã¢ã¼ããã¹ãã[email protected]ãã®ãã¡ã¤ã«ã/home/user/tmp/file1ãããªã¢ã¼ãã»ãã¹ãã[email protected]ãã®ã/home/user/tmp/ãã¸ã³ãã¼ããä¾ã§ãã
1 |
$ scp user1@192.168.10.1:/home/user/tmp/file1 user2@192.168.10.2:/home/user/tmp/ |
ãã£ã¬ã¯ããªãã¨ã³ãã¼ãè¡ã
ãã£ã¬ã¯ããªãã¨å帰çã«ã³ãã¼ããå ´åãã-rããªãã·ã§ã³ãæå®ãã¾ãã
ãªã¢ã¼ããã¹ãã®ã/home/user/tmpã以ä¸ã®ãã¡ã¤ã«ã¨ãã£ã¬ã¯ããªãã¹ã¦ããã¼ã«ã«ã®ã~/tmpãã«ã³ãã¼ããä¾ã§ãã
1 |
$ scp -r user1@192.168.10.1:/home/user/tmp ~/tmp |
æ å ±ãä¿æããã¾ã¾ã³ãã¼ãè¡ã
ã³ãã¼å ãã¡ã¤ã«ã¨ãã£ã¬ã¯ããªã®æ´æ°æéãã¢ã¯ã»ã¹æéããã¼ããã·ã§ã³ãä¿æããã¾ã¾è»¢éããå ´åã¯ãã-pããªãã·ã§ã³ãæå®ãã¾ãããã ããææè ãã°ã«ã¼ãã®æ å ±ã¯å¼ãç¶ããã¾ããã
ãªã¢ã¼ããã¹ãã®ã/home/user/tmpã以ä¸ã®ãã¡ã¤ã«ã¨ãã£ã¬ã¯ããªãã¹ã¦ãããã¡ã¤ã«ã®æ´æ°æéãã¢ã¯ã»ã¹æéããã¼ããã·ã§ã³ãä¿æãã¦ãã¼ã«ã«ã®ã~/tmpãã«ã³ãã¼ããä¾ã§ãã
1 2 3 4 |
$ scp -p -r user@192.168.10.1:/home/user/tmp ~/tmp # è¤æ°ã®ãªãã·ã§ã³ã¯ã-prãã®ããã«ã¾ã¨ãã¦ããã $ scp -pr user@192.168.10.1:/home/user/tmp ~/tmp |