• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

Copying Your Local SSH Public Key To A Remote Machine/Server In Mac OS

Command Line · August 11, 2015

When it comes to working with your servers (or any remote machine for that matter), public key encryption is a must. The basics are: you register a public key on the server-side and then use your private key to authenticate with the remote machine.

So you’ve generated a new SSH keypair or you have your existing SSH keys in the form of id_rsa or whatever. Now you want to push them to your remote server so you can use your private key to login?

cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'cat >> .ssh/authorized_keys && echo "Public key successfully copied"'

You of course will want to replace <user> and <hostname> with their appropriate values and supply any other required values.

You should never copy and paste shell commands off of the internet, so lets quickly explain what the above code does. We actually are calling multiple commands one after the other, rather than one method that does everything for us.

  • cat ~/.ssh/id_rsa.pub — The concatenate command can do many things, but here we are simply concatenating the contents of our public key and then it is returned to the terminal window
  • | — We then pipe the returned contents of our public key file to an ssh call
  • ssh @ — This is where we connect to our remote machine where we want to save the key
  • cat >> .ssh/authorized_keys — Assuming everything went okay, we then use cat command to store the piped contents of our public key into the authorized_keys file

Dwayne

Leave a Reply Cancel reply

0 Comments
Inline Feedbacks
View all comments

Primary Sidebar

Popular

  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • How To Mock uuid In Jest
  • Which Neural DSP Archetype Plugins Should You Buy?
  • How to Copy Files Using the Copy Webpack Plugin (without copying the entire folder structure)
  • Removing A Character From The Start/End of a String In Javascript
  • How To Convert FormData To JSON Object
  • How To Correctly Use Semantic HTML5 <article>, <main> and <section> Tags
  • Wild Natural Deodorant Review
  • How To Get Last 4 Digits of A Credit Card Number in Javascript

Recent Comments

  • Thebe on How to Remove the My Sites Menu From the WordPress Admin Bar
  • Maccas worker jn the 2000s on Dear McDonald’s: bring back the Warm Cookie Sundae, you cowards
  • Anamika Singh on Testing Event Listeners In Jest (Without Using A Library)
  • Stefan on A List of WordPress Gutenberg Core Blocks
  • pandammonium on A List of WordPress Gutenberg Core Blocks

Copyright © 2022 · Dwayne Charrington · Log in

wpDiscuz