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 email@example.com
This creates a new SSH key, using the provided email as a label.
Generating public/private algorithm key pair.
- 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]
- 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:
- 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.
- Ensure the ssh-agent is running.
#Start the ssh-agent in the background
$ eval “$(ssh-agent -s)”
Agent pid 59566
- 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
- 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/id_rsa.pub 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”