# Ssh private keys backup and migration



## blind0ne (Feb 8, 2022)

Hi, I have an app on my phone where rsa keypair is stored, I want use them on my freebsd host, but when I'm trying to login at locked server the folowing message appear:

```
Load key "/home/min/.ssh/id_rsa": invalid format
miner@19***: Permission denied (publickey).
```

The format on my phone was like 'RSA KEY'
and generated on computer is seems to be shorter then copied from phone: 51 vs 27 lines.

How should I backup keys at all?


----------



## SirDice (Feb 8, 2022)

Keys can be stored in different formats. And it looks like you're trying to use the wrong formatted keys on FreeBSD. RSA, DSA, etc. are _types_ of keys, which tells you exactly nothing about the format of how those keys are stored.


----------



## blind0ne (Feb 8, 2022)

SirDice said:


> Keys can be stored in different formats. And it looks like you're trying to use the wrong formatted keys on FreeBSD.


I'm trying to use RSA format and there is OPENSSH, the original app on phone is terminus.


----------



## SirDice (Feb 8, 2022)

RSA is a _type_ of key, not a format. On FreeBSD ssh-keygen(1) produces an RSA key that looks like this:

```
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEAr5/AzVkeIjApLdW9pO1EpXN9mhDh+ZtGG8VdDNvuCxH2aNtmjxxu
ou7po+tUeet3riS4QXcmZ2zBtrTob7NV6Yr//pAbM/P/NxtTMMEOEmdzfFlWBFDiqbtSe+
B+ZlcmAn9iN5l2NGPPK/wTn13Mi4I0UB1I2HnHRN6bYcVGKHrZ7iDAABwuU0seLSxN3/3O
vXgp8+bMDHCbdkJy3JhJPjbfBaWmw5zVABtc0iAKOEfM/jtsKkK8B07HM1gxVKCG0LK7j8
3SZm6PkXkJw9LL0fmPokUjwzbILCf0I6pM9Ojcb042swQ7+RDuF7XuhC1W6Wv100HKv4xg
+nkiGHW1OQAAA9DYR6sJ2EerCQAAAAdzc2gtcnNhAAABAQCvn8DNWR4iMCkt1b2k7USlc3
2aEOH5m0YbxV0M2+4LEfZo22aPHG6i7umj61R563euJLhBdyZnb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9BHgOiAuf0i9oPB
SLPLeunD0CbKsg0oqMhkRnzPIxllLwuqieZbZP+Shi817a/e93kE0eLGIG4oFr0hwgBDaY
cDYL08/TIBT5FaCTEwAAABdkaWNlQG1vbGx5LmRpY2VsYW4uaG9tZQEC
-----END OPENSSH PRIVATE KEY-----
```

Don't worry about me posting a private key, it's just one I generated and then destroyed.


----------



## blind0ne (Feb 8, 2022)

SirDice said:


> RSA is a _type_ of key, not a format.


https://www.cryptosys.net/pki/rsakeyformats.html looking here right now, Thanks


----------



## blind0ne (Feb 8, 2022)

Both of my keys seems to be in base64 but with different length


----------

