Copy file Linux from one server to another
Show
In my last article I shared the steps to encrypt a file using gpg key in Linux. Now in this article I will share various commands and tools which you can use to securely copy file from one server to another in Linux. There are additionally other ways to transfer files which I cannot cover here for example you can also use HTTPS to upload and download files. I may write another article with detail list of steps to use HTTPS and curl for secure file upload and download.If you wish to copy files between Windows and Linux then you can always use Samba but since here we are targeting file transfer between two Linux machines, I will not share any steps related to Samba configuration. Some more articles on related topic you may be interested in
In computing, the SSH File Transfer Protocol (also Secure File Transfer Protocol, or SFTP) is a network protocol that provides file access, file transfer, and file management over any reliable data stream. SFTP is easy to work with: You enter You can also automate the file transfer using SFTP in shell script, or you can also use one liner SFTP commands to perform file transfer rather than interactive sessions. [[email protected] ~]$ sftp -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no Password: Once you give the password of sftp> ls -l -rw-r----- 1 root root 401 Dec 7 11:53 new_key.pub -rw-r----- 1 deepak users 9 Dec 10 14:13 pwd.txt drwxr-xr-x 2 root root 4096 Nov 28 11:38 scripts -rw-r--r-- 1 root root 0 Dec 10 14:07 test_file Next to copy file from host to client (i.e. upload a file from host to client) sftp> put /home/deepak/pwd.txt .
Uploading /home/deepak/pwd.txt to /home/deepak/./pwd.txt
/home/deepak/pwd.txt 100% 9 26.6KB/s 00:00 To copy a directory and all it's content use (-r). Here /home/deepak/mydir is available on my host machine which I am copying to the connected client node under current working directory. Có thể bạn quan tâmsftp> put -r /home/deepak/mydir .
Entering /home/deepak/mydir/ So the file was successfully uploaded. You can verify the same sftp> ls
new_key.pub pwd.txt scripts test_file Next copy a file from client node to your host server. I have a file 'test_file' on my client node under '/home/deepak/test_file' sftp> get test_file /tmp/
Fetching /home/deepak/test_file to /tmp/test_file Validate the same on your host server # ls -l /tmp/test_file -rw-r----- 1 deepak deepak 0 Dec 10 14:09 /tmp/test_file You can get more supported options from the man page of Using RSYNC to copy file from one server to anotherrsync is a utility that you can use to copy file from one server to another very easily, and there are many options available to allow you to be very specific about how you want the data transferred. Another aspect that makes rsync flexible is the many ways you can manipulate the source and target directories. However, you don't even have to use the network; you can even copy data from one directory to another on the same server. Copying a file within the same server from one location to another # rsync -r /home/deepak/mydir/test /tmp/ Here we are using NOTE: To copy files between two servers # rsync -av test :/tmp/ Password: sending incremental file list sent 44 bytes received 12 bytes 22.40 bytes/sec total size is 5 speedup is 0.09 Using SCP to copy file from one server to anotherA useful alternative to rsync is the Secure Copy (SCP) utility to copy file from one server to another, which comes bundled with OpenSSH. It allows you to quickly copy files from one node to another. If your goal is to send a single file or a small number of files to another machine, SCP is a great tool you can use to get the job done. To utilize SCP, we'll use the scp command. Since you most likely already have OpenSSH installed, you should already have the scp command available Using SCP is very similar in nature to rsync. The command requires a source, a target, and a filename. To transfer a single file from your local machine to another, the resulting command would look similar to the following: # scp -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null host_list :/tmp/ Password: host_list 100% 30 83.2KB/s 00:00 If you do not specifiy the target directory while doing scp, then the home directory of the target user will be used are destination. # scp -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null host_list : Password: IMPORTANT NOTE: With our previous # scp -r -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null /home/deepak/mydir : Password: Using NFS to share file from one server to anotherA Network File System (NFS) is a great method of sharing files between Linux or UNIX servers. I have written another article with detailed steps to setup NFSv4 and NFSv3 with examples in RHEL/CentOS 7 and 8 Linux On my RHEL node I have installed # cat /etc/exports /share *(rw,no_root_squash) /share 10.0.2.0/255.255.255.0(rw,no_root_squash)
NOTE: Next restart your # systemctl restart nfs-server.service To check the list of shares currently exported # exportfs -v /share 10.0.2.0/255.255.255.0(rw,sync,wdelay,hide,no_subtree_check,sec=sys,secure,no_root_squash,no_all_squash) /share Now try to mount the directory [[email protected] ~]# mount -t nfs node2:/share /mnt So our directory mount is successful, Next validate the content [[email protected] ~]# cd /mnt/ [[email protected] mnt]# ls test1 test2 We can validate the same on our client node using below command [[email protected] mnt]# mount | grep share node2:/share on /mnt type nfs4 (rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.0.2.20,local_lock=none,addr=10.0.2.21) NOTE: After successfully mounting the share on the client node, you can copy the file locally to your node. # cp -av /mnt/* /tmp/ ‘/mnt/test1’ -> ‘/tmp/test1’ ‘/mnt/test2’ -> ‘/tmp/test2’ Using SSHFS to copy file from one server to anotherSSH Filesystem (SSHFS) is a file sharing solution similar to NFS and Samba. NFS and Samba are great solutions for designating file shares but these technologies may be more complex than necessary if you want to set up a temporary file-sharing service to use for a specific period of time. SSHFS allows you to mount a remote directory on your local machine, and have it treated just like any other directory. The mounted SSHFS directory will be available for the life of the SSH connection and can be used to copy file from one server to another. Drawbacks of using SSHFS
SSHFS is part of EPEL repository, which you can install using yum # yum -y install sshfs For SSHFS to work, we'll need a directory on both your local Linux machine as well as a remote Linux server. SSHFS can mount any directory from the remote server where you have SSH access. Here I am mounting [[email protected] ~]# sshfs [email protected]:/share /mnt [email protected]'s password: Now validate the content of [[email protected] ~]# cd /mnt/ [[email protected] mnt]# ls test1 test2 [[email protected] mnt]# mount | grep share [email protected]:/share on /mnt type fuse.sshfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0) Now you can copy the files from [[email protected] mnt]# cp -av * /tmp/ ‘test1’ -> ‘/tmp/test1’ ‘test2’ -> ‘/tmp/test2’ Once your copying is complete, manually unmount the
respective directory. There are two ways to do so. First, we can use the [[email protected] ~]# umount /mnt/ You can also use HTTPS for file sharing, although it would be more like of file uploading and downloading via GET and PUT using curl command. Lastly I hope the commands from this article to copy file from one server to another in Linux or Unix was helpful. So, let me know your suggestions and feedback using the comment section. Can we copy file from one server to another in Linux?The scp tool relies on SSH (Secure Shell) to transfer files, so all you need is the username and password for the source and target systems. Another advantage is that with SCP you can move files between two remote servers, from your local machine in addition to transferring data between local and remote machines.
What are the two ways to copy files from one server to another?FTP and SCP are helpful way if you want to transfer files from local to remote and vice versa. If you use SCP, it still can transfer files between two remote servers.
|
Bài Viết Liên Quan
Cách đổi tài khoản Facebook sang Garena
Gần đây có rất nhiều bạn hỏi cách chuyển tài khoản facebook sang Garena. Chính vì thế, mà hôm nay mình sẽ chia sẻ cho các bạn cách làm trong bài viết này. Mục ...
Cách sử dụng máy massage digital therapy machine
Máy massage trị liệu Digital Therapy Machine SYK-208 Bạn làm việc văn phòng, ngồi học bài, Lái xe đường dài, hoặc phải ngồi một chỗ quá lâu, dẫn đến cơ thể ...
Top 20 cửa hàng 711 Huyện Nghi Lộc Nghệ An 2022
Có tổng 113 đánh giá về Top 20 cửa hàng 711 Huyện Nghi Lộc Nghệ An 2022 Siêu thị Điện máy XANH Quán Hành, Nghi Lộc 53 đánh ...
Tải minecraft cho máy yêu win 7
Duới đây là các thông tin và kiến thức về chủ đề tải minecraft cho pc yếu hay nhất do chính tay đội ngũ chúng tôi biên soạn và tổng hợp: 1. Cách tải ...
Tất cả các công thức toán lớp 10
Nhằm giúp các em đỡ nhàm chán, có cái nhìn rõ hơn khi học môn Toán đại 10, Newshop xin chia sẻ đến các em toàn bộ kiến thức, công thức toán 10 được tổng ...
Công nghệ nào sau đây không thuộc công nghệ tế bào thực vật
Quá trình nào sau đây không thuộc công nghệ tế bào?A. Dung hợp tế bào trần khác loàiB. Nhân bản vô tính cừu ĐôlyC. Nuôi cấy hạt phấn, sau đó gây lưỡng ...
Rủi ro trong nghiên cứu, thử nghiệm, áp dụng tiến bộ khoa học, kỹ thuật và công nghệ
Khoa học & Công nghệ › Khoa học XH & NV8/2/2018 14:32 Rủi ro trong nghiên cứu thử nghiệm, áp dụng tiến bộ khoa học, kỹ thuật và công nghệ không phải chịu ...
Lỗi mạng wifi hay bị Limited nên laptop không bắt được wifi từ điện thoại
Nếu như bạn đang sử dụng Laptop để làm việc thì có lẽ đã ít nhất một lần bạn đã gặp phải lỗi máy tính không nhận được sóng Wifi, hoặc thậm chí ...
Quả việc sử dụng địa chỉ ô trong công thức em hay chỉ ra những ưu điểm của nó
Nếu bạn mới dùng Excel dành cho web, bạn sẽ nhanh chóng tìm thấy rằng nó nhiều hơn là chỉ một lưới trong đó bạn nhập số trong các cột hoặc hàng. Có, bạn ...
Cách sử dụng máy chiếu sanyo
Hướng dẫn sử dụng máy chiếu (Projector)Đăng lúc: 25-04-2016 11:40:00 AM - Đã xem: 9536Hướng dẫn sử dụng máy chiếu (Projector)Trong thời đại ngày nay việc áp ...
Hiển thị ra màn hình các số dương có trong mảng
Đề bài: Nhập mảng số nguyên từ bàn phím. Tính trung bình cộng các số âm, tổng các số dương và đưa kết quả ra màn hình. Mô tả giá trị đầu vào: Dòng ...
Đào tạo theo kiểu chương trình hóa với sự trợ giúp của máy tính có ưu điểm là
You are using an out of date browser. It may not display this or other websites correctly.You should upgrade or use an alternative browser. Thread starter Hưng Thịnh Start date Jul 19, ...
Tổng đài bảo hành máy lọc nước Kangaroo
DANH SÁCH TRUNG TÂM BẢO HÀNH KANGAROO TRÊN TOÀN QUỐC Công ty TNHH Trực tuyến Kangaroo Việt Úc là đơn vị duy nhất chịu trách nhiệm bán và giới thiệu sản phẩm ...
Đầu tư theo chiều sâu, đổi mới trang thiết bị và công nghệ không nhằm mục đích
Phương pháp: Kiến thức bài 26 – Cơ cấu ngành công nghiệpCách giải: Việc đầu tư theo chiều sâu, đổi mới trang thiết bị và công nghệ trong công nghiệp ...
Máy bay trực thăng nặng bao nhiều kg
Dmitry ShorkovLần đầu tiên, tại Nhà máy sản xuất trực thăng mang tên “Mil” ở Moskva (MVZ), máy bay trực thăng vận tải quân sự Mi-26-T2V được đưa ra giới ...
Top 6 công tắc wifi tuya viền vàng tốt nhất 2022
Công Tắc Thông Minh Wifi TUYA Hình Chữ Nhật Cảm Ứng 1-2-3-4 Nút Điều Khiển Qua App + Giọng Nói BH 1 Năm Đã bán: ...
Máy rửa chén Bosch Điện máy XANH
Theo dõi đơn hàng 0Giỏ hàng Hotline mua hàng 1900 2628 Trang chủ / Gia dụng / Máy Rửa Chén - Sấy Chén Trang chủ Trò chuyện 19 Giỏ ...
Nâng cấp máy triệt lông khoẻ lên 2tech
Cùng với sự phát triển của xã hội thì tính thẩm mỹ ngày càng tăng. Do đó hiện nay nhiều chị em rất quan tâm tới vấn đề triệt lông trên cơ thể để có ...