Skip to content
Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
Close

Search

Home/DevOps/Chef/Serialize SSH and RSA private keys to store them in a Chef Data Bag
ChefDevOps

Serialize SSH and RSA private keys to store them in a Chef Data Bag

By Laszlo Pinter
November 23, 2016 2 Min Read
0

To send RSA private keys to instances, store them in encrypted data bags. The data bag item is a JSON file that contains keys and values inline.

Use base64 encoding

Base64 encoding converts binary data to ASCII format to represent special characters, like line breaks as ASCII text. The result will be larger, 8 / 6th of the original size, as every 8 bit ASCII character only represents 6 bits of data.

To convert a file to base 64 and save it as another file

cat test.pem | base64 > test.pem.base64

If we need the result on the computer’s clipboard to paste it into a field on the screen

cat test.pem | base64 | pbcopy

To use the encoded string we need to decode it in the Chef cookbook.

Replace the newline characters with \n

To place the multi-line RSA key into the value part of the JSON file, we need to replace the new line characters with the “\n” text.

In Atom

on Mac and Windows

  1. Open the RSA key file in Atom,
  2. Press Command-F on Mac, Ctrl-F on Windows to open the Find and Replace window,
  3. On the right side click the Use Regex button,
  4. In the search field enter
    \r\n
  5. In the replace with field enter
    \\n
  6. Press the Replace All button

In Visual Studio Code

on Mac and Windows

  • Press Command-F on Mac, Ctrl-F on Windows to open the Find dialog
  • Select the Use Regular Expression button
  • Enter \n into the find, \\n into the replace field

In Notepad++

on Windows

  • Open the RSA key file in Notepad++,
  • In the Search menu select Replace…,
  • Select Extended mode in the Search Mode section,
  • Enter \r\n to the Find what text box ( if the key was generated on a Windows computer using GitBash, search for \n )
  • Enter \\n  to the Replace with text box
  • Press the Replace All button

You can place the single line key into any encrypted Data Bag file. See Data Bags on Data Bag encryption.

Tags:

Chefclouddata_bagDevOps
Author

Laszlo Pinter

Follow Me
Other Articles
Previous

Where to find the Drupal site version

Next

The FastCGI process exited unexpectedly

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Last Changes

  • DevOps Engineering part 1. (Mac) - Make your Macintosh easier to use June 25, 2026
  • Japan travel tips June 22, 2026
  • How to stop the rain and snow in Cities: Skylines II June 20, 2026
  • Cities: Skylines II Developer Mode June 20, 2026
  • 'CSII_MANAGEDPATH' has incorrect path(s) when building Cities: Skylines II mod June 20, 2026

Tags

.NET .NETcore 3Dprinting ASP.NET Core AutodeskInventor AWS C# Chef cloud DevOps Docker EntityFramework Games Git Go iOS iPad iPhone iPod Java Kubernetes Linux MacOSX MSSQL MVC Node.js Packer PowerShell Python RDS RightScale Ruby security Splunk TeamCity Terraform TestKitchen Tomcat Ubuntu Vagrant VirtualBox VisualStudio Windows WordPress Xcode

Recent Comments

  • Zengei László on MyHeritage családfa exportálása és küldése emailben
  • Raúl Castillo on DynDns update error
  • MICHAEL on Windows Media Player 12 cannot find the album information
  • Nargis on Configure Epson ET-3850 scanning on Windows 11
  • Venczelné Zemen Erika on Delta S2302 termosztát programozása

–

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright 2026 — Pinter Computing. All rights reserved.