{"id":14302,"date":"2025-02-07T15:06:05","date_gmt":"2025-02-07T15:06:05","guid":{"rendered":"https:\/\/rapyd.cloud\/blog\/?p=14302"},"modified":"2025-02-07T15:06:06","modified_gmt":"2025-02-07T15:06:06","slug":"scp-command-in-linux","status":"publish","type":"post","link":"https:\/\/rapyd.cloud\/blog\/scp-command-in-linux\/","title":{"rendered":"What Is the scp Command in Linux? [Examples Provided]"},"content":{"rendered":"\n<p>Moving files securely between systems isn\u2019t always easy\u2014especially when you\u2019re dealing with sensitive data and can\u2019t afford any slip-ups.. That\u2019s where the <strong>scp<\/strong> command in Linux comes into play. Short for \u201csecure copy,\u201d scp encrypts your files during transit (thanks to the SSH protocol) so that nosy third parties can\u2019t snoop on your data. Whether you\u2019re migrating server configs, sending scripts to colleagues, or just moving a folder of cat memes to your VPS, scp has you covered. Below, we\u2019ll walk through how scp works, why it\u2019s useful, and some handy examples to kickstart your learning.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"why-use-scp-instead-of-other-methods\" class=\"wp-block-heading\"><strong>Why Use <\/strong><strong>scp<\/strong><strong> Instead of Other Methods?<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Encryption Built-In<\/strong>: Unlike plain copy commands, scp automatically safeguards your files with SSH encryption.<\/li>\n\n\n\n<li><strong>Remote to Remote<\/strong>: You can shuffle files between two remote servers without downloading them to your local machine first.<\/li>\n\n\n\n<li><strong>User-Friendly<\/strong>: The syntax feels familiar if you\u2019ve ever used cp for local copies\u2014just add your SSH credentials and paths.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"basic-scp-syntax\" class=\"wp-block-heading\"><strong>Basic <\/strong><strong>scp<\/strong><strong> Syntax<\/strong><\/h2>\n\n\n\n<p>The general format looks like this:<\/p>\n\n\n\n<p>scp [options] [source] [destination]\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>options<\/strong>: Special flags you can enable for debugging, limiting speed, recursive copying, etc.<\/li>\n\n\n\n<li><strong>source<\/strong>: Where your file currently lives (either locally or on a remote server).<\/li>\n\n\n\n<li><strong>destination<\/strong>: Where you want the file to end up (again, can be local or remote).<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"1-copying-a-local-file-to-a-remote-server\" class=\"wp-block-heading\"><strong>1. Copying a Local File to a Remote Server<\/strong><\/h2>\n\n\n\n<p>So you\u2019ve got a file named notes.txt on your local machine, and you want to upload it to a remote server. Here\u2019s how:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp \/path\/to\/local\/notes.txt username@remote_host:\/remote\/path\/<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Replace username with your actual username on the remote server.<\/li>\n\n\n\n<li>remote_host can be an IP address or a domain name.<\/li>\n\n\n\n<li>If the file is small, this will happen almost instantly; for larger files, you\u2019ll see a progress bar.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"2-copying-a-remote-file-to-your-local-system\" class=\"wp-block-heading\"><strong>2. Copying a Remote File to Your Local System<\/strong><\/h2>\n\n\n\n<p>Sometimes you need to grab something from a server\u2014maybe logs or a config file. Reverse the direction:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp username@remote_host:\/path\/to\/remote\/backup.tar.gz \/local\/path\/<\/code><\/pre>\n\n\n\n<p>Now scp will fetch backup.tar.gz from the remote server and plop it into your local \/local\/path\/.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"3-copying-a-directory-recursively\" class=\"wp-block-heading\"><strong>3. Copying a Directory (Recursively)<\/strong><\/h2>\n\n\n\n<p>Transferring one file is fine, but what if you\u2019ve got an entire directory of files you need to move? Just tack on the <strong>-r<\/strong> flag for recursion:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp -r \/local\/directory\/ username@remote_host:\/remote\/directory\/<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This grabs every file, folder, and subfolder nested inside \/local\/directory\/.<\/li>\n\n\n\n<li>Make sure you include the trailing slash \/ so that scp copies the contents instead of creating an extra subdirectory.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"4-copying-between-two-remote-systems\" class=\"wp-block-heading\"><strong>4. Copying Between Two Remote Systems<\/strong><\/h2>\n\n\n\n<p>A lesser-known trick: you can move files between two remote hosts without touching your local machine:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp username1@remote_host1:\/path\/to\/file.txt username2@remote_host2:\/path\/to\/destination\/<\/code><\/pre>\n\n\n\n<p>Think of it like telling one server to pass your file directly to another. Handy if your local bandwidth is limited.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"extra-options-you-should-know\" class=\"wp-block-heading\"><strong>Extra Options You Should Know<\/strong><\/h2>\n\n\n\n<p><strong>Custom SSH Port with -P<br><\/strong> If your server runs on, say, port <strong>2222<\/strong> instead of the standard <strong>22<\/strong>, you can specify that like so<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp -P 2222 \/local\/file.txt username@remote_host:\/remote\/path\/<\/code><\/pre>\n\n\n\n<p><strong>Limit Bandwidth with -l<br><\/strong> On a slow or shared connection? Avoid hogging all the bandwidth<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp -l 200 \/local\/file.txt username@remote_host:\/remote\/path\/<\/code><\/pre>\n\n\n\n<p>&nbsp;The 200 here means 200 Kbps\u2014enough to get the job done without saturating the network.<\/p>\n\n\n\n<p><strong>Verbose Output with -v<br><\/strong> Having trouble diagnosing a stalled transfer? Verbose mode spills all the behind-the-scenes details<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp -v \/local\/file.txt username@remote_host:\/remote\/path\/<\/code><\/pre>\n\n\n\n<p>&nbsp;This prints out each step, which can be a lifesaver for debugging.<br><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"common-pitfalls-and-pro-tips\" class=\"wp-block-heading\"><strong>Common Pitfalls and Pro Tips<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Check Your Paths<\/strong>: Typos in file paths can lead to errors like \u201cNo such file or directory.\u201d Always verify you\u2019ve spelled everything correctly.<\/li>\n\n\n\n<li><strong>Permissions<\/strong>: Make sure your user account on the remote server has write permissions in the target folder.<\/li>\n\n\n\n<li><strong>SSH Keys<\/strong>: Setting up public key authentication (instead of password auth) makes scp both more secure and more convenient.<\/li>\n\n\n\n<li><strong>Security<\/strong>: Even though scp uses SSH, always keep an eye on which users have access to your server. A strong SSH setup plus consistent updates is a must for safe file transfers.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"why-system-administrators-love-scp\" class=\"wp-block-heading\"><strong>Why System Administrators Love <\/strong><strong>scp<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Reliability<\/strong>: It rarely fails if your SSH credentials are in order and your network is stable.<\/li>\n\n\n\n<li><strong>No Third-Party Tools<\/strong>: No need to install separate clients; scp comes standard on most Linux distros (and macOS).<\/li>\n\n\n\n<li><strong>Automation<\/strong>: You can script scp commands (with SSH keys) for automated backups, deployments, or log transfers.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"wrapping-up\" class=\"wp-block-heading\"><strong>Wrapping Up<\/strong><\/h2>\n\n\n\n<p>When it comes to moving files around safely and easily, the <strong>scp<\/strong><strong> command<\/strong> in Linux is a real MVP. It\u2019s simple, gets the job done, and leans on SSH to protect your data in transit. Whether you\u2019re archiving log files, distributing scripts, or just tinkering around with personal projects, scp is a staple tool you\u2019ll want in your arsenal.<\/p>\n\n\n\n<p><strong>Ready to try it out?<\/strong> The next time you need to shuffle files between machines, open your terminal and give scp a spin. The secure, efficient transfer might just become your new go-to method\u2014no extra steps, no third-party apps, just a single command that does it all. Happy copying!<\/p>\n","protected":false},"excerpt":{"rendered":"Moving files securely between systems isn\u2019t always easy\u2014especially when you\u2019re dealing with sensitive data and can\u2019t afford any&hellip;\n","protected":false},"author":20,"featured_media":9751,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","om_disable_all_campaigns":false,"_eb_data_table":"","csco_post_fleet_bg_color":"linear-gradient(135deg,rgb(6,147,227) 0%,rgb(138,68,204) 100%)","csco_post_fleet_image_id":9751,"csco_post_fleet_text_color":"","full_width_enabled":false,"csco_singular_sidebar":"","csco_page_header_type":"fleet","csco_header_bg_color":"","csco_appearance_masonry":"","csco_page_load_nextpost":"","csco_post_video_location":[],"csco_post_video_location_hash":"","csco_post_video_url":"","csco_post_video_bg_start_time":0,"csco_post_video_bg_end_time":0,"footnotes":""},"categories":[44,46],"tags":[220,219],"class_list":{"0":"post-14302","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-hosting","8":"category-website-security","9":"tag-linux","10":"tag-scp","11":"csco-post-header-type-fleet","12":"cs-entry","13":"cs-video-wrap"},"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/posts\/14302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/comments?post=14302"}],"version-history":[{"count":2,"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/posts\/14302\/revisions"}],"predecessor-version":[{"id":16373,"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/posts\/14302\/revisions\/16373"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/media\/9751"}],"wp:attachment":[{"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/media?parent=14302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/categories?post=14302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rapyd.cloud\/blog\/wp-json\/wp\/v2\/tags?post=14302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}