{"id":1858,"date":"2016-08-27T14:09:13","date_gmt":"2016-08-27T19:09:13","guid":{"rendered":"http:\/\/wildow.com\/?p=1858"},"modified":"2016-08-27T14:54:10","modified_gmt":"2016-08-27T19:54:10","slug":"easy-way-to-copy-files-over-ssh","status":"publish","type":"post","link":"https:\/\/wildow.com\/?p=1858","title":{"rendered":"Easy Way To Copy Files Over SSH"},"content":{"rendered":"<p><a href=\"https:\/\/serversuit.com\/community\/technical-tips\/view\/easy-way-to-copy-files-over-ssh.html\">https:\/\/serversuit.com\/community\/technical-tips\/view\/easy-way-to-copy-files-over-ssh.html<\/a><\/p>\n<p>SSH is a protocol that can help you manage a remote computer, as well as\u00a0let you upload and download files. You can also use SSH keys instead of a password!<br \/>\nCopying files requires the secure copy command, which is actually pretty simple:<\/p>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\">scp<\/span> [options] [original file] [destination_file]<\/code><\/pre>\n<p>The syntax for the <strong>[destination file]<\/strong>\u00a0 portion\u00a0is usually where users have the most difficulty.\u00a0When you are addressing a remote file\u00a0you should use this format:<\/p>\n<pre><code class=\"hljs perl\">user@server:p<strong>ath\/to\/file<\/strong><\/code><\/pre>\n<p>The server, in this case, can either be an IP address or a URL. After the IP\/URL address\u00a0you&#8217;ll\u00a0just write the standard file path after a colon.. Here\u2019s an example:<\/p>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\">scp<\/span> \u2013P <span class=\"hljs-number\">40050<\/span> Desktop\/filename.txt nms@<span class=\"hljs-number\">192.168.1.50<\/span>:~\/Desktop\/filename.txt<\/code><\/pre>\n<p>We used the <strong>-P<\/strong>\u00a0flag here\u00a0which let\u2019s you specify the port you want to use. Otherwise, it&#8217;ll just default\u00a0to port 22. Note that this flag <em>is <\/em>case sensitive\u00a0and should be uppercase. \u00a0Depending on how your system is configured\u00a0you might not need to use this flag.<br \/>\nThen\u00a0I just used\u00a0the original file, which is \u201cfilename.txt,\u201d and it is located in the \u201cDesktop\u201d directory. The destination file is located in \u201c<strong>~\/Desktop\/filename.txt<\/strong>\u201d. The command has been executed by the user \u201c<strong>nms<\/strong>\u201d on computer \u201c<strong>192.168.1.50<\/strong>\u201d.<br \/>\nWhat if you need to do the reverse operation and copy a file from a remote server to your local machine?\u00a0You would then switch the source and destination within the same command.<br \/>\nHere\u2019s an example:<\/p>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\">scp<\/span> \u2013P <span class=\"hljs-number\">40050<\/span> nms@<span class=\"hljs-number\">192.168.1.20<\/span>:~\/Desktop\/filename.txt Desktop\/filename.txt<\/code><\/pre>\n<p>I will have copied a file from the folder\u201d <strong>~\/Desktop\/<\/strong>\u201d of the remote computer to the \u201cDesktop\u201d folder on my computer.<br \/>\nIf you want to copy a whole directory\u00a0you will have to use the <strong>-r<\/strong>\u00a0flag,\u00a0in lowercase. The command would then look like this:<\/p>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\">scp<\/span> -r \u2013P <span class=\"hljs-number\">40050<\/span> nms@<span class=\"hljs-number\">192.168.1.20<\/span>:~\/Desktop\/filename.txt Desktop\/filename.txt<\/code><\/pre>\n<p>You can actually \u201ccombine\u201d flags. Instead of using:<\/p>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\">scp<\/span> \u2013P \u2013r \u2026<\/code><\/pre>\n<p>You can use:<\/p>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\">scp<\/span> \u2013Pr \u2026<\/code><\/pre>\n<p><strong>SSH Without Passwords<\/strong><\/p>\n<p>Secure copy is great as you can put it in scripts and let it perform backups to remote computers. However, you won\u2019t always be around to provide the password. Being asked to enter a password every time you run the script can get tiresome.Thankfully, you can use key files to get around this problem. You can generate two key files; a private one for your computer\u00a0and a public one for the remote computer. You\u2019ll then be able to use these instead of a password<\/p>\n<p>First use the following command on your computer:<\/p>\n<pre><code class=\"hljs\">ssh-keygen \u2013t rsa<\/code><\/pre>\n<p>The command will generate two keys which should be kept in:<\/p>\n<pre><code class=\"hljs\">~\/.ssh\/<\/code><\/pre>\n<p>with the name \u201cid_rsa.pub\u201d for the public key and the name \u201cid_rsa\u201d for the private key.<br \/>\nYou\u2019ll be asked about where to save the keys. If you want to use the defaults,\u00a0just hit Enter and\u00a0you will also be asked to type a passphrase. You can hit the Enter key again to leave it blank.<br \/>\nYou should then copy the file with the public key to the remote computer. Now the \u201cscp\u201d command can be used to put the keys in place, like this:<\/p>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\">scp<\/span> -r \u2013P <span class=\"hljs-number\">40050<\/span> .ssh\/id_rsa.pub nms@<span class=\"hljs-number\">192.168.1.20<\/span>:~\/.ssh\/authorized_keys2<\/code><\/pre>\n<p>The destination of the key on the remote server will be located in:<\/p>\n<pre><code class=\"hljs\">~\/.ssh\/authorized_keys2<\/code><\/pre>\n<p>And you\u2019re done!<br \/>\nYou\u2019ve learned how to use the scp command by itself, as well as generating key files, and using scp with key key files to copy data without using a password.\u00a0Secure copy over SSH is very flexible. You can use the command for small operations\u00a0or in conjunction with server control panels for security and flexibility in bulk operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/serversuit.com\/community\/technical-tips\/view\/easy-way-to-copy-files-over-ssh.html SSH is a protocol that can help you manage a remote computer, as well as\u00a0let you upload and download files. You can also use SSH keys instead of a password! Copying files requires the secure copy command, which is &#8230; <a class=\"more-link\" href=\"https:\/\/wildow.com\/?p=1858\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1858","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wildow.com\/index.php?rest_route=\/wp\/v2\/posts\/1858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wildow.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wildow.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wildow.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wildow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1858"}],"version-history":[{"count":1,"href":"https:\/\/wildow.com\/index.php?rest_route=\/wp\/v2\/posts\/1858\/revisions"}],"predecessor-version":[{"id":1859,"href":"https:\/\/wildow.com\/index.php?rest_route=\/wp\/v2\/posts\/1858\/revisions\/1859"}],"wp:attachment":[{"href":"https:\/\/wildow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wildow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wildow.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}