使用rcp命令實現從遠程機器拷貝文件


rcp:遠程文件復制
使用rcp命令可以在遠程主機之間復制文件,如果同時指定2個以上的文件或目錄,且最后的目的地是一個已經存在的目錄,則他會把前面指定的所有文件或目錄復制到該目錄中。
rcp命令語法:
rcp  【選項】【文件1】【文件2】
rcp   【選項】 【文件】 【目錄】
rcp   【選項】
rcp命令選項含義
選項
含義
-p
嘗試保留副本的修改時間和原文件的模式
-x
在主機之間傳輸加密所有信息
-r
如果原文件是目錄,,復制該目錄中每個字樹
-D<端口>
指定連接到遠程主機上的端口
-N
使用網絡連接在本地主機上復制文件
-c<緩存文件>
更改默認憑據緩存文件
需要說明的是,rcp不提示輸入口令,它通過rsh命令來執行拷貝。
CentOS6安裝配置rsh如下

基本信息:
節點一:
ip:192.168.8.166 
主機名:hadrtest01
節點二:
ip:192.168.8.250 
主機名:hadrtest02

1、兩節點分別安裝rsh,rsh-server包是否已經安裝

yum -y install rsh rsh-server

2、修改/etc/xinetd.d/rlogin確保disable = no這一行

# default: on
# description: rlogind is the server for the rlogin(1) program. The server \
# provides a remote login facility with authentication based on \
# privileged port numbers from trusted hosts.
service login
{
 socket_type = stream
 wait = no
 user = root
 log_on_success += USERID
 log_on_failure += USERID
 server = /usr/sbin/in.rlogind
 disable = no
}

節點二同樣修改

3、修改/etc/xinetd.d/rsh確保disable = no這一行

[root@hadrtest01 ~]# cat /etc/xinetd.d/rsh
# default: on
# description: The rshd server is the server for the rcmd(3) routine and, \
# consequently, for the rsh(1) program. The server provides \
# remote execution facilities with authentication based on \
# privileged port numbers from trusted hosts.
service shell
{
 socket_type = stream
 wait = no
 user = root
 log_on_success += USERID
 log_on_failure += USERID
 server = /usr/sbin/in.rshd
 disable = no
}

節點二同樣修改

4、編輯/etc/securetty,添加rexec、rsh、rlogin三行

echo "

rexec

rsh

rlogin

" >> /etc/securetty


5、編輯/etc/hosts,添加兩節點的ip,主機名

[root@hadrtest01 ~]# cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.8.166 hadrtest01

192.168.8.250 hadrtest02


節點二同樣修改

6、修改~/.rhosts ,添加節點一,節點二主機名,ip

[root@hadrtest01 ~]# cat ~/.rhosts

hadrtest01 root

hadrtest02 root

[root@hadrtest02 ~]# cat ~/.rhosts

hadrtest01 root

hadrtest02 root

7、兩節點分別啟動服務
重啟:

service xinetd restart

開機啟動:

chkconfig xinetd on

8、測試
節點一:

[root@hadrtest01 ~]# rsh hadrtest02

Last login: Tue Feb 16 17:44:56 from hadrtest01

[root@hadrtest02 ~]#


不輸入密碼登錄節點二表示安裝成功

節點二:

[root@hadrtest02 ~]# rsh hadrtest01

Last login: Tue Feb 16 17:39:35 from hadrtest02

[root@hadrtest01 ~]#

不輸入密碼登錄節點一表示安裝成功

注意:按照上述操作完在之后,如果測試時提示要輸入密碼 或者測試時提示connection refush可以使用如下方法解決

1、在linux的命令提示符中輸入#ntsysv rsh,然后按enter鍵

2、在打開的服務中找到rlogin,如果前面沒有*,則按空格鍵,在前面加上*號之后,點擊OK,退出

3、重啟服務service xinetd restart

 

rcp命令解析:

1、以用戶root將遠程主機192.168.92.130上的/home/1111.sh文件復制到本地的當前目錄

2、將遠程主機192.168.92.130上的/home/test目錄復制到本地的當前目錄

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM