在两台Linux机器上面建立信任关系以及使用SCP命令复制文件:操作环境,机器A:10.0.238.81 cognos10用户 ,机器B:10.0.238.114 cognos10用户 A机器IP为 IPA, B机器IP为IPB
1,使用SCP命令将A机器文件temp.txt 传输到B机器/home/cognos/code/cognos/TEMPTEST 目录下面,B机器是用户是cognos10
********************************************************[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)? yesWarning: 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 ********************************************************
会提示输入B机器cognos10用户的密码,密码填写正确后,传输成功。
2,使用SCP命令将B机器/home/cognos/code/cognos/TEMPTEST 目录下面的temp.txt文件传输到A机器当前目录********************************************************cd /home/cognos/code/cognos/TEMPTESTSCP cognos10@10.0.238.114:/home/cognos/code/cognos/TEMPTEST/temp.txt .(这里有个点,表示当前目录)********************************************************密码输入正确,传输成功
如果文件名称相同,SCP直接覆盖该文件。
3,使用SCP命令的时候要输入密码,这在写shell脚本的时候很麻烦,下面介绍一下如何不用输入密码
A机器向B机器传输的时候不用输密码的方法:
在两台机器上面建立信任关系,即可解决此问题
----A机器上的操作----********************************************************[cognos10@biserver ~]$ cd /home/cognos10/.ssh[cognos10@biserver .ssh]$ ssh-keygen -t rsaGenerating 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@biserverThe key's randomart image is:+--[ RSA 2048]----+| ++ o. || .... o. || E ..o... . || . o oooB o .||. . . S .= * . || . . . . . || . || || |+-----------------+********************************************************一直回车下去
执行完成后会在/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/ TEMPTESTtemp.txt 100% 0 0.0KB/s 00:00
转载于:https://www.cnblogs.com/088-p/p/7382436.html