configuration of ssh key on balena production OS

1. Generating a new SSH key: -
1.Open git bash
2.Paste the text below, substituting in your GitHub email address.
$ ssh-keygen -t rsa -b 4096 -C
This creates a new SSH key, using the provided email as a label.

Generating public/private algorithm key pair.

  1. When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.

Enter a file in which to save the key (/c/Users/you/.ssh/id_algorithm): [Press enter]

  1. At the prompt, type a secure passphrase. For more information, see “Working with SSH key passphrases.”

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

2. Adding your SSH key to the ssh-agent:

  1. Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key. If you have GitHub Desktop installed, you can use it to clone repositories and not deal with SSH keys.
  2. Ensure the ssh-agent is running.
    #Start the ssh-agent in the background
    $ eval “$(ssh-agent -s)”

Agent pid 59566

  1. Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
    $ ssh-add ~/.ssh/id_ed25519
  2. Add the SSH key to your account on GitHub. For more information, see "Adding a new SSH key to your GitHub account.

3. Add an ssh key to balenaCloud:
1.To add an SSH key, go to the Preferences page of balenaCloud and select the SSH Keys tab.
2.When used with a production balenaOS, this feature requires balena CLI v13.3.0 or later, and balenaOS v2.44.0 or later. Otherwise, an SSH key must be added to the device’s config.json file, sshKeys section.
3.SSH key has been uploaded to balena (Preferences → SSH keys). Take a copy of the key.
4.The public key file ~/.ssh/ exists and has the same contents as the uploaded key (preferences->>SSH keys).
5.You have a private key file ~/.ssh/id_rsa which corresponds to the public key you checked in above point.
6.Go to balenaCloud device terminal and hit below command:
Cat /mnt/boot/config.json | jq
7.Copy that config. json in notepad and add ssh key in that config.json file.
Note: Please be very careful when editing config. json - a broken config.json will prevent your device from coming online and starting balena properly. cat /mnt/boot/config.json | jq should display no errors if your edit was correct.
8.Copy the updated config.json file and paste it in cat /mnt/boot/confg.json.
9.Restart the device and check and confirm the ssh key details are there in config.json file.Now, go to balena cli and hit the below commands, it will allow root access.
balena ssh “device-uuid”

Hey @smitanannor

I am a little confused by your post as I wasn’t able to find a question. Are you just documenting how to do something in the forums?

Hey @anujdeshpande ,
Yes , it just documented.