• 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
  • Waiting for an Element to Exist With JavaScript
  • Thoughts on the Flipper Zero
  • How To Get Last 4 Digits of A Credit Card Number in Javascript
  • How To Mock uuid In Jest
  • How To Paginate An Array In Javascript
  • Reliably waiting for network responses in Playwright
  • How to Copy Files Using the Copy Webpack Plugin (without copying the entire folder structure)
  • Wild Natural Deodorant Review

Recent Comments

  • Dwayne on Is Asking Developers How to Write FizzBuzz Outdated?
  • kevmeister68 on Is Asking Developers How to Write FizzBuzz Outdated?
  • Kevmeister68 on Start-Ups and Companies That Embrace Work From Anywhere Will Be More Likely to Survive the Coming Recession in 2023
  • kevmeister68 on What Would Get People Back Into the Office?
  • Dwayne on PHP Will Not Die

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz