<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="https://publishpress.com/"
	>

<channel>
	<title>SCP Archives - Tomoshare</title>
	<atom:link href="https://blog.tomosia.com.vn/tag/scp/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.tomosia.com.vn/tag/scp/</link>
	<description>Kênh chia sẻ kiến thức Tomosia Việt Nam</description>
	<lastBuildDate>Fri, 06 Oct 2023 06:10:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.tomosia.com.vn/wp-content/uploads/2023/09/cropped-icon-32x32.png</url>
	<title>SCP Archives - Tomoshare</title>
	<link>https://blog.tomosia.com.vn/tag/scp/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[SCP command] Sử dụng SCP để chuyển dữ liệu</title>
		<link>https://blog.tomosia.com.vn/scp-command-su-dung-scp-de-chuyen-du-lieu/</link>
					<comments>https://blog.tomosia.com.vn/scp-command-su-dung-scp-de-chuyen-du-lieu/#comments</comments>
		
		<dc:creator><![CDATA[admin_tomosia]]></dc:creator>
		<pubDate>Fri, 06 Oct 2023 02:22:41 +0000</pubDate>
				<category><![CDATA[OS & Command]]></category>
		<category><![CDATA[SCP]]></category>
		<guid isPermaLink="false">https://blog.tomosia.com.vn/?p=443</guid>

					<description><![CDATA[<p>Chúng ta thường xuyên có nhu cầu di chuyển file từ local sang remote hoặc ngược lại, đặc&#8230;</p>
<p>The post <a href="https://blog.tomosia.com.vn/scp-command-su-dung-scp-de-chuyen-du-lieu/">[SCP command] Sử dụng SCP để chuyển dữ liệu</a> appeared first on <a href="https://blog.tomosia.com.vn">Tomoshare</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="720" height="480" src="http://blog.tomosia.com.vn/wp-content/uploads/2023/10/scp-command-featured_hucd75439ca17b14e4fd17e89ca6e3b5e5_104738_0x480_resize_q75_h2_box_2.webp" alt="" class="wp-image-449" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2023/10/scp-command-featured_hucd75439ca17b14e4fd17e89ca6e3b5e5_104738_0x480_resize_q75_h2_box_2.webp 720w, https://blog.tomosia.com.vn/wp-content/uploads/2023/10/scp-command-featured_hucd75439ca17b14e4fd17e89ca6e3b5e5_104738_0x480_resize_q75_h2_box_2-300x200.webp 300w, https://blog.tomosia.com.vn/wp-content/uploads/2023/10/scp-command-featured_hucd75439ca17b14e4fd17e89ca6e3b5e5_104738_0x480_resize_q75_h2_box_2-380x253.webp 380w" sizes="(max-width: 720px) 100vw, 720px" /></figure>



<p class="has-text-align-left" style="font-size:16px">Chúng ta thường xuyên có nhu cầu di chuyển file từ local sang remote hoặc ngược lại, đặc biệt khi quản lý hoặc triển khai mã trên server.&nbsp;Một cách hiệu quả để thực hiện việc này là thông qua&nbsp;<strong>Secure Copy Protocol</strong> <strong>(SCP)</strong>&nbsp;, một công cụ được tích hợp trong&nbsp;<strong>SSH</strong>&nbsp;(Secure Shell).&nbsp;Blog này sẽ hướng dẫn bạn cách sử dụng SCP trên các nền tảng Linux như Ubuntu, Linux Mint và Debian, cùng nhiều nền tảng khác.</p>



<h2 id="ssh-va-scp-co-ban-de-truyen-tep-an-toan" class="wp-block-heading"><strong>SSH và SCP: Cơ bản để truyền tệp an toàn</strong></h2>



<p><strong>SSH</strong> là từ viết tắt của Secure Shell, là một giao thức được sử dụng để truy cập server một cách an toàn.&nbsp;Được tích hợp trong hệ sinh thái SSH này là <strong>Secure Copy Protocol (&nbsp;SCP)</strong> là một công cụ hiệu quả để truyền tệp giữa local và server.&nbsp;Cú pháp của nó gần giống với lệnh <strong>CP</strong> (sao chép), nhưng nó hướng đến việc remote.</p>



<h2 id="scp-command-syntax" class="wp-block-heading"><strong>SCP Command Syntax</strong></h2>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp [options] [username@IP]:/[directory and file name] [destination username@IP]:/[directory]" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> [options] [username@IP]:/[directory and file name] [destination username@IP]:/[directory]</span></span></code></pre></div>



<p>Trong đó:</p>



<ul class="wp-block-list">
<li><strong>options:</strong> là các tùy chọn của lệnh SCP như mật mã, cấu hình&nbsp;ssh, cổng ssh, giới hạn…</li>



<li><strong>username@IP:</strong> là username và IP của máy có file bạn muốn thao tác. Nó sẽ có dạng giống như root@123.123.123.12</li>



<li><strong>:/</strong>&nbsp;báo cho SCP command biết sau đó sẽ là thư mục nguồn</li>



<li><strong>[directory and file name]</strong>:&nbsp;đường dẫn chứa file, và tên của nó. Nó có dạng /tomosia/blog/SCP.pdf</li>



<li><strong>[destination username@IP]</strong>&nbsp;là username và IP của máy đích</li>



<li><strong>[destination directory]</strong>: là thư mục đích, nơi file được lưu</li>
</ul>



<p>Ví dụ: </p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp -p tomo@192.168.1.1:/tomosia/blog/SCP.pdf tms@162.168.1.2:/tms/destination" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> -p tomo@192.168.1.1:/tomosia/blog/SCP.pdf tms@162.168.1.2:/tms/destination</span></span></code></pre></div>



<p><em><span style="text-decoration: underline;">Một số tùy chọn được sử dụng trong SCP:</span></em></p>



<ul class="wp-block-list" type="1">
<li>–P port xác định chính xác cổng vào của server (port mặc định của TCP là 22)</li>



<li>–c cipher giúp bạn xác định thuật toán mã hóa bạn muốn dùng. Một số giá trị bạn có thể đặt vào là ‘aes256-ctr’, ‘aes256-cbc’, ‘blowfish-cbc’, ‘arcfour’, ‘arcfour128’, ‘arcfour256’, ‘cast128-cbc’, aes128-ctr’, ‘aes128-cbc’, ‘aes192-ctr’, ‘aes192-cbc’, and 3des-cbc’. Lựa chọn mặc định trong cấu hình là ‘AnyStdCipher’</li>



<li>–q sẽ vận hành trong chế độ im lặng, có nghĩa là chỉ có các lỗi nghiêm trong mới hiện lên.</li>



<li>–r là recursive copying, có nghĩa là bao gồm tất cả thư mục con.</li>



<li>-4 hoặc -6 được dùng khi bạn muốn chọn phiên bản protocol IPv4 hay IPv6.</li>



<li>–p là “preserve”, dùng để lưu lại thời gian chỉnh sửa và thuộc tính của file.</li>



<li>–u sẽ xóa file nguồn sau khi chuyển đổi hoàn tất.</li>



<li>–c giúp nén dữ liệu khi truyền.</li>
</ul>



<h2 id="nhung-dieu-can-luu-y" class="wp-block-heading"><strong>Những điều cần lưu ý</strong></h2>



<p>Vì SCP sử dụng mã hóa SSH, bạn sẽ cần dùng mật khẩu ssh để chuyển file. Hơn nữa, nó còn cần quyền đọc trên máy tính của bạn copy <em>từ</em> và quyền viết trên máy tính bạn copy <em>tới</em>.</p>



<p>Để chứng thực kết nối, bạn sẽ cần tạo ssh key pari trong terminal bằng lệnh sau:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="ssh-keygen -t rsa" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #F8F8F2">ssh-</span><span style="color: #FF79C6">keygen</span><span style="color: #F8F8F2"> -t rsa</span></span></code></pre></div>



<p>Copy khóa này vào máy remote bằng lệnh:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="ssh-copy-id user@remote_machine" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #F8F8F2">ssh-copy-</span><span style="color: #FF79C6">id</span><span style="color: #F8F8F2"> user@remote_machine</span></span></code></pre></div>



<p>Khi bạn đã chứng thực trên máy tính từ xa, public key sẽ được copy và đã có thể chuyển file.</p>



<p>Nếu bạn không nhớ mật khẩu root cho cả 2 máy, bạn có thể dùng ssh client để chọn file private identity key để RSA được đọc tự động.</p>



<p>Với protocol 2, đường dẫn mặc định của host key là&nbsp;<strong>~/.ssh/id_dsa</strong>, còn protocol version 1 nó đặt ở&nbsp;<strong>~/.ssh/id_rsa</strong>. Sau đó, bạn phải cần tìm file back-up của privaet và public key để ssh command tự động dùng chúng.</p>



<p>Đối với đường dẫn&nbsp;<strong>/back-up/home/jack/.ssh</strong>&nbsp;, lệnh này sẽ trông như sau:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="ssh -i /back-up/home/user/.ssh/id_dsa user@yourserver.servername.domain" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">ssh</span><span style="color: #F8F8F2"> -i /back-up/home/user/.ssh/id_dsa user@yourserver.servername.domain</span></span></code></pre></div>



<p>Nếu bạn đang chuyển file lớn, chúng tôi khuyên dùng tmux session hoặc chạy lệnh trong một&nbsp;screen&nbsp;khác. Ngoài ra, bạn còn có thể chọn -v để buộc scp hiển thị bất kỳ lỗi kết nối, chứng thực hay cấu hình nào.</p>



<div class="wp-block-media-text alignfull is-stacked-on-mobile is-vertically-aligned-center has-background" style="background-color:#3ab4b7;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--30);grid-template-columns:33% auto"><figure class="wp-block-media-text__media"><img decoding="async" width="723" height="723" src="http://blog.tomosia.com.vn/wp-content/uploads/2023/10/pro-tip.png" alt="" class="wp-image-469 size-full" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2023/10/pro-tip.png 723w, https://blog.tomosia.com.vn/wp-content/uploads/2023/10/pro-tip-300x300.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2023/10/pro-tip-150x150.png 150w, https://blog.tomosia.com.vn/wp-content/uploads/2023/10/pro-tip-80x80.png 80w, https://blog.tomosia.com.vn/wp-content/uploads/2023/10/pro-tip-380x380.png 380w" sizes="(max-width: 723px) 100vw, 723px" /></figure><div class="wp-block-media-text__content">
<p>Lệnh mặc định có giá trị là –overwrite [yes] có nghĩa là quá trình này sẽ ghi đè file có cùng tên và vị trí mà không đưa ra cảnh báo. Bạn có thể thêm  <strong>–overwrite no</strong> hay <strong>–overwrite ask</strong> trong scp command để chắc chắn rằng việc ghi đè đã được thông qua.</p>
</div></div>



<h2 id="copy-du-lieu-bang-scp-command-linux-giua-hai-he-thong" class="wp-block-heading"><strong>Copy dữ liệu bằng SCP Command Linux</strong> <strong>giữa hai hệ thống</strong></h2>



<p class="has-medium-font-size"><strong>#1: Từ local sang remote</strong></p>



<p>Chúng ta sẽ copy một file có tên&nbsp;<strong>tms-scp.zip</strong>, tới máy tính từ xa có tên&nbsp;<strong>root</strong>. Sau tên username sẽ là IP máy remote</p>



<p>Ví dụ:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing</span></span></code></pre></div>



<p>Nếu bạn không có cấu hình ssh client tự động được cài đặt, bạn sẽ được hỏi nhập mật khẩu từ máy tính từ xa như sau:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="blogtms@191.162.0.2’s password:
novel3.zip   100% 0 0.0KB/s 00:00" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #F8F8F2">blogtms@191.162.0.2’</span><span style="color: #FF79C6">s</span><span style="color: #F8F8F2"> password:</span></span>
<span class="line"><span style="color: #F8F8F2">novel3.</span><span style="color: #FF79C6">zip</span><span style="color: #F8F8F2">   100% </span><span style="color: #BD93F9">0</span><span style="color: #F8F8F2"> 0.0KB/s 00:00</span></span></code></pre></div>



<p>Nếu port trên máy remote khác port mặc định 22. Trong trường hợp này, bạn cần chỉ định port cho nó:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp -P 2322 /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> -P </span><span style="color: #BD93F9">2322</span><span style="color: #F8F8F2"> /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing</span></span></code></pre></div>



<p>Nếu bạn muốn thay đổi tên file trong quá trình copy, bạn cần nhập lệnh sau trong SCP Linux:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing/new-tms-scp.zip" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing/new-tms-scp.zip</span></span></code></pre></div>



<p>Nếu muốn copy một thư mục có tất cả file và thư mục con, sử dụng tham số –<strong>r</strong>&nbsp;như chúng tôi đã giải thích ở trên:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp -r /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> -r /tms/blog/tms-scp.zip blogtms@191.162.0.2:/blog/writing</span></span></code></pre></div>



<p class="has-medium-font-size"><strong>#2: Từ remote về local</strong></p>



<p>Trong trường hợp này, bạn chỉ cần đảo ngược chỗ vị trí nguồn và vị trí đích là được. Lần này, chúng tôi đang copy file&nbsp;<strong>tms-scp.zip&nbsp;</strong>từ máy remote về local:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp blogtms@191.162.0.2:/blog/writing/tms-scp.zip /tms/blog/tms-scp.zip" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> blogtms@191.162.0.2:/blog/writing/tms-scp.zip /tms/blog/tms-scp.zip</span></span></code></pre></div>



<p>Sau đó bạn sẽ cần nhập thông tin đăng nhập SSH, hoặc bạn đã buộc SSH client sử dụng private key trên máy tính của bạn.</p>



<p class="has-medium-font-size"><strong>#3: Từ remote A sang remote B</strong></p>



<p>Để copy từ remote A sang remote B, bạn sẽ cần nhập password cho cả 2 tài khoản của cả 2 máy để chạy lệnh trong terminal.</p>



<p>Ví dụ:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp blogtms@191.162.0.2:/blog/writing/tms-scp.zip tms@103.145.92.1:/publishing" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> blogtms@191.162.0.2:/blog/writing/tms-scp.zip tms@103.145.92.1:/publishing</span></span></code></pre></div>



<p>Lệnh trên copy file nguồn&nbsp;<strong>/blog/writing/tms-scp.zip</strong>&nbsp;từ host đầu tiên đến host thứ 2. Để copy folder, chỉ cần thêm option&nbsp;<strong>-r&nbsp;</strong>và xác định đường dẫn thư mục thay vì file bên trong nó, như chúng tôi đã làm.</p>



<p>Trong điều kiện bình thường, file sẽ đi thẳng tới remote host. Tuy nhiên, nếu bạn muốn chuyển hướng để đi thông qua máy của bạn, bạn có thêm option&nbsp;<strong>-3</strong>:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="scp -3 blogtms@191.162.0.2:/blog/writing/tms-scp.zip tms@103.145.92.1:/publishing" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">scp</span><span style="color: #F8F8F2"> -3 blogtms@191.162.0.2:/blog/writing/tms-scp.zip tms@103.145.92.1:/publishing</span></span></code></pre></div>



<h2 id="tong-ket-ve-lenh-scp-trong-linux" class="wp-block-heading">Tổng kết về lệnh SCP trong Linux</h2>



<p>Lệnh&nbsp;<strong>SCP</strong> trong Linux là một trong những phương pháp hiệu quả và an toàn nhất để truyền tệp giữa local và remote được kết nối qua mạng.&nbsp;Cho dù bạn cần SCP từ local đến remote hay thực hiện các thao tác sao chép tệp SSH, hướng dẫn này đều đáp ứng được nhu cầu của bạn.</p>



<p>Luôn nhớ xác minh các hoạt động SCP của bạn để đảm bảo các tệp chính xác đã được chuyển.</p>



<p class="has-medium-font-size">Thanks for reading &#8230;</p>
<p>The post <a href="https://blog.tomosia.com.vn/scp-command-su-dung-scp-de-chuyen-du-lieu/">[SCP command] Sử dụng SCP để chuyển dữ liệu</a> appeared first on <a href="https://blog.tomosia.com.vn">Tomoshare</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.tomosia.com.vn/scp-command-su-dung-scp-de-chuyen-du-lieu/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
