在兩臺Linux機器上面創建信任關係以及使用SCP命令複製文件:
操做環境,機器A:10.0.238.81 cognos10用戶 ,機器B:10.0.238.114 cognos10用戶 A機器IP爲 IPA, B機器IP爲IPBshell
1,使用SCP命令將A機器文件temp.txt 傳輸到B機器/home/cognos/code/cognos/TEMPTEST 目錄下面,B機器是用戶是cognos10dom
********************************************************
[cognos10@biserver ~]$ scp /home/cognos/code/cognos/TEMPTEST/temp.txt cognos10@10.0.238.114:/home/cognos/code/cognos/ TEMPTESTThe authenticity of host '10.0.238.114 (10.0.238.114)' can't be established.
RSA key fingerprint is 62:28:0e:ee:47:13:fe:c6:e1:5d:f5:ec:ab:75:46:e2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.238.114' (RSA) to the list of known hosts.
cognos10@10.0.238.114's password:
temp.txt 100% 0 0.0KB/s 00:00
********************************************************ssh
會提示輸入B機器cognos10用戶的密碼,密碼填寫正確後,傳輸成功。ide
2,使用SCP命令將B機器/home/cognos/code/cognos/TEMPTEST 目錄下面的temp.txt文件傳輸到A機器當前目錄
********************************************************
cd /home/cognos/code/cognos/TEMPTEST
SCP cognos10@10.0.238.114:/home/cognos/code/cognos/TEMPTEST/temp.txt .(這裏有個點,表示當前目錄)
********************************************************
密碼輸入正確,傳輸成功spa
若是文件名稱相同,SCP直接覆蓋該文件。code
3,使用SCP命令的時候要輸入密碼,這在寫shell腳本的時候很麻煩,下面介紹一下如何不用輸入密碼server
A機器向B機器傳輸的時候不用輸密碼的方法:ci
在兩臺機器上面創建信任關係,便可解決此問題it
----A機器上的操做----
********************************************************
[cognos10@biserver ~]$ cd /home/cognos10/.ssh
[cognos10@biserver .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cognos10/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/cognos10/.ssh/id_rsa.
Your public key has been saved in /home/cognos10/.ssh/id_rsa.pub.
The key fingerprint is:
05:61:d9:7e:33:72:a7:f4:85:48:59:2a:8b:a4:0a:52 cognos10@biserver
The key's randomart image is:
+--[ RSA 2048]----+
| ++ o. |
| .... o. |
| E ..o... . |
| . o oooB o .|
|. . . S .= * . |
| . . . . . |
| . |
| |
| |
+-----------------+
********************************************************
一直回車下去io
執行完成後會在/home/cognos10/.ssh 目錄下面生成兩個文件 id_rsa,id_rsa.pub
把 id_rsa.pub文件傳輸到B機器上面,並修改位 authorized_keys.pub
[cognos10@biserver .ssh]$ scp id_rsa.pub cognos10@10.0.238.114:/home/cognos10/.ssh/authorized_keys
再次使用SCP命令由A機器傳輸到 B機器上面的時候就不會輸入密碼。
[cognos10@biserver .ssh]$ scp /home/cognos/code/cognos/TEMPTEST/temp.txt cognos10@10.0.238.114:/home/cognos/code/cognos/ TEMPTEST
temp.txt 100% 0 0.0KB/s 00:00