Geek Posted May 5, 2011 Posted May 5, 2011 <div class="KonaBody"><p><img src="http://osxdaily.com/wp-content/uploads/2011/05/transfer-source-code-ssh.jpg" alt="Transfer Source Code and Text over SSH" title="transfer-source-code-ssh" width="620" height="294" class="aligncenter size-full wp-image-15643" /></p> <p>Do you have some source code, text, or a command string that you want to securely transfer from one Mac to another? Combining the <a href="http://osxdaily.com/2007/03/05/manipulating-the-clipboard-from-the-command-line/">command line clipboard tools pbcopy and pbpaste</a> with SSH we can do exactly that, and it doesn’t matter where the other Mac is located: be it LAN, WAN, or anywhere. </p> <p>Here is the basic command syntax:</p> <p><code>pbpaste | ssh username@ipaddress pbcopy</code></p> <p>For transferring data on a LAN, you can use another <a href="http://osxdaily.com/2007/02/15/changing-your-macs-computer-name/">Macs hostname</a> or IP address.</p> <p>This is highly useful because <em>using this method is secure</em>, plus <em>it will not mangle special characters or code</em> in the manner that many email and IM clients will.</p> <p><strong>Receiving Mac Needs SSH Enabled</strong> <img src="http://osxdaily.com/wp-content/uploads/2011/05/enable-remote-login-ssh-mac1.jpg" alt="Enable remote login and SSH in Mac OS X" title="enable-remote-login-ssh-mac" width="235" height="205" class="alignright size-full wp-image-15647" /> In order for this to work, the recipients Mac must have “Remote Login” enabled, this allows anyone to connect to the machine securely with SSH and a password. This is easy for anyone to do: </p> <ul> <li>Launch System Preferences, click on “Sharing”</li> <li>Select the checkbox next to “Remote Login”</li> </ul> <p>Now that is Remote Login is enabled, I copy the the command I want to transfer to my Macs clipboard and use the syntax structure shown above.</p> <p><strong>Example</strong> For example, I want to send a complex command line string to a friend of mine who is a novice computer user. Let’s say it’s a variation of <a href="http://osxdaily.com/2011/04/22/monitor-mac-os-x-filesystem-usage-access-with-opensnoop/">lsof to monitor internet access of certain apps</a> because it’s relatively short, but it could be anything and I typically use this for source code. Here’s my sample string to send:</p> <p><code>lsof -nPi | cut -f 1 -d " "| uniq</code></p> <p>I select that text and copy it to my local clipboard. Now, let’s assume my friends Mac is located in another building but on the same network, a common scenario in large corporate or educational campuses. I know his IP address is 192.168.50.175 and his Macs username is “Steve”, I’ll also need Steves password so that I can connect to his Mac and access his clipboard.</p> <p><code>pbpaste | ssh steve@192.168.50.175 pbcopy</code></p> <p>I’ll enter Steves password when requested, and his clipboard will immediately have the string I selected on my clipboard on his. Now he can paste that <a href="http://osxdaily.com/category/command-line/">command</a> into the Terminal to execute it, or do whatever else. </p> <p><strong>Securely Transfers Large Text Blocks & Source Code Between Macs</strong> This also works with very large blocks of text which makes it perfect for sending lengthy clips of source code or other text data that you either don’t want to email for security reasons, or that would otherwise get mangled from sending over Instant Messenger clients.</p> <p>This seems to only work with plain text data, but if you can get it working with anything else let us know in the comments.</p> </div> <p><a href="http://feedads.g.doubleclick.net/~a/AX99rVyIyuiL29xmdCeyH5icsrg/0/da"><img src="http://feedads.g.doubleclick.net/~a/AX99rVyIyuiL29xmdCeyH5icsrg/0/di" border="0" ismap="true"></img></a><br/> <a href="http://feedads.g.doubleclick.net/~a/AX99rVyIyuiL29xmdCeyH5icsrg/1/da"><img src="http://feedads.g.doubleclick.net/~a/AX99rVyIyuiL29xmdCeyH5icsrg/1/di" border="0" ismap="true"></img></a></p><div class="feedflare"> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=gk8lCi8-7HY:gMwJvAViOAk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=gk8lCi8-7HY:gMwJvAViOAk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=gk8lCi8-7HY:gMwJvAViOAk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=gk8lCi8-7HY:gMwJvAViOAk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=gk8lCi8-7HY:gMwJvAViOAk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=gk8lCi8-7HY:gMwJvAViOAk:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=gk8lCi8-7HY:gMwJvAViOAk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=qj6IDK7rITs" border="0"></img></a> </div><img src="http://feeds.feedburner.com/~r/osxdaily/~4/gk8lCi8-7HY" height="1" width="1"/> View the full article
Recommended Posts