SSH Public and Private Keys

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
kalfusisagod
DD-WRT Novice


Joined: 29 Mar 2012
Posts: 13

PostPosted: Thu Mar 29, 2012 8:56    Post subject: SSH Public and Private Keys Reply with quote
Hello, I've searched this on the forum and google and couldn't find what I was looking for. Plus the search on this board can't search by subject line only and returns a ton of unrelated posts on "SSH public private keys" or any combination of that with or without quotes. I've read the wiki, have all my DynDNS and port forwarding set up. This is just a general question.

Let's just stick to the basics. My question is on SSH. I understand the concept of this but not the specifics. I've generated the public and private keys using Putty on windows and ssh on a mac and still don't understand what goes to what. For example, I know the public key needs to go into the "authorized keys" on the DD-WRT router but do I include EVERYTHING or just the key.

For example, my mac produces a public key of

ssh-dss AAAAB3NzaC1k...Bw4E= joe@ MacBook-Pro.local

while putty generates

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20120329"
AAAAB3NzaC1...deXU=
---- END SSH2 PUBLIC KEY ----


Do I have to just copy the key alone or do I need all the "meta data" or whatever it is? I also understand that line breaks need to be taken out, so I have been doing that.

Next question, do I paste the private key on the computer that I'm trying to use to SSH into my router? I've been SSHing into my router using my mac and pasted the private key into the known_hosts file under the .ssh folder but it keeps putting my public key in there. So this would be my known_host file on my Mac

domain.com,68.125.78.32 ssh-rsa MIBuw...XAUd <--- Private Key

Inside terminal on the Mac, I would run ssh root@domain.com and would get

The authenticity of host 'domain' (68.125.78.32)' can't be established
RSA key fingerprint is f6:xx:xx:xx:xx...
Are you sure you want to continue connecting (yes/no)


Selecting no kicks me out and does nothing, selecting yes gets me into DD-WRT's ssh with my router password. After inspecting the known_host file on my Mac after selecting yes puts the ROUTER'S PUBLIC key in there. So my question is what is the point of the private key? And how do I know that my ssh is really secure using a public/private key pair? I can throw commands at my router through SSH but just want to ensure my connection is secure. Thank you.
Sponsor
slobodan
DD-WRT Guru


Joined: 03 Nov 2011
Posts: 1557
Location: Zwolle

PostPosted: Thu Mar 29, 2012 23:03    Post subject: Reply with quote
You could import the private key into puttygen and then save it as private and as public key in putty format. DD-WRT accepts copy/paste from puttygen.
_________________
2 times APU2 Opnsense 21.1 with Sensei

2 times RT-AC56U running DD-WRT 45493 (one as Gateway, the other as AP, both bridged with LAN cable)

3 times Asus RT-N16 shelved

E4200 V1 running freshtomato 2020.8 (bridged with LAN cable)

3 times Linksys WRT610N V2 converted to E3000 and 1 original E3000 running freshtomato 2020.8 (bridged with LAN cable)


kalfusisagod
DD-WRT Novice


Joined: 29 Mar 2012
Posts: 13

PostPosted: Sat Mar 31, 2012 3:10    Post subject: Reply with quote
so the public key is set into the host (dd wrt router) and the client (my macbook)? And the private key is ONLY used to recover the public key if lost? Thanks.
slobodan
DD-WRT Guru


Joined: 03 Nov 2011
Posts: 1557
Location: Zwolle

PostPosted: Sat Mar 31, 2012 21:50    Post subject: Reply with quote
kalfusisagod wrote:
so the public key is set into the host (dd wrt router) and the client (my macbook)? And the private key is ONLY used to recover the public key if lost? Thanks.

No, putty/ssh uses the private key to authenticate the connection to the router. So, putty/ssh has to have the private key. In the router you enter the public key corresponding to that private key. If you don't have a private key, generate one, e.g. with ssh-keygen . It should not be the same as the router's private key, because it is perhaps specific to the firmware build, so everybody with the same firmware could have the same private key for the router.

_________________
2 times APU2 Opnsense 21.1 with Sensei

2 times RT-AC56U running DD-WRT 45493 (one as Gateway, the other as AP, both bridged with LAN cable)

3 times Asus RT-N16 shelved

E4200 V1 running freshtomato 2020.8 (bridged with LAN cable)

3 times Linksys WRT610N V2 converted to E3000 and 1 original E3000 running freshtomato 2020.8 (bridged with LAN cable)


amrogers3
DD-WRT Novice


Joined: 05 Nov 2010
Posts: 48

PostPosted: Sat May 19, 2012 22:40    Post subject: Reply with quote
So to follow up with question above....

I am using a mac with OSX Leopard 10.5

When using ssh-keygen I get something that looks like this:

ssh-rsa AAAAFASREFX%#ASDc== aaron@aarons-macbook-pro-15.local

Which isn't in the format:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20120329"
AAAAB3NzaC1...deXU=
---- END SSH2 PUBLIC KEY ----

What do I need to do? Add headers to my key or use a different method to generate keys?

Thanks.
hatcreek68
DD-WRT Novice


Joined: 29 Nov 2016
Posts: 27

PostPosted: Fri Dec 22, 2017 17:35    Post subject: Reply with quote
I was just fighting this - and only was able to use the SSH key by logging in as ROOT not some other username.

also to reiterate what other's said: copy/paste public key from the putty window (to capture the right format), don't need to save the public key.
Alozaros
DD-WRT Guru


Joined: 16 Nov 2015
Posts: 6446
Location: UK, London, just across the river..

PostPosted: Sat Dec 23, 2017 4:36    Post subject: Reply with quote
nope its not like that....🌝
_________________
Atheros
TP-Link WR740Nv1 ---DD-WRT 55630 WAP
TP-Link WR1043NDv2 -DD-WRT 55723 Gateway/DoT,Forced DNS,Ad-Block,Firewall,x4VLAN,VPN
TP-Link WR1043NDv2 -Gargoyle OS 1.15.x AP,DNS,QoS,Quotas
Qualcomm-Atheros
Netgear XR500 --DD-WRT 55779 Gateway/DoH,Forced DNS,AP Isolation,4VLAN,Ad-Block,Firewall,Vanilla
Netgear R7800 --DD-WRT 55819 Gateway/DoT,AD-Block,Forced DNS,AP&Net Isolation,x3VLAN,Firewall,Vanilla
Netgear R9000 --DD-WRT 55779 Gateway/DoT,AD-Block,AP Isolation,Firewall,Forced DNS,x2VLAN,Vanilla
Broadcom
Netgear R7000 --DD-WRT 55460 Gateway/SmartDNS/DoH,AD-Block,Firewall,Forced DNS,x3VLAN,VPN
NOT USING 5Ghz ANYWHERE
------------------------------------------------------
Stubby DNS over TLS I DNSCrypt v2 by mac913
Alozaros
DD-WRT Guru


Joined: 16 Nov 2015
Posts: 6446
Location: UK, London, just across the river..

PostPosted: Sat Dec 23, 2017 10:49    Post subject: Reply with quote
for example add this key to ssh field in DD-WRT services

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAqVwX3i/Eujwg92i+HkiWXWTDTdYqamXfb6gcMVtoW6cwVEC+EdjoIbWqvASFv1d8Dg24QMGZV4L3S3o9iJDCqqulw2O0Ul1qKT3kfI0jZBbFhH/9v1+YjBMlMEBMysWeRCu/gCXPi/wDxolpSSIIkmUqzEbw1d83Hr8LMcYSt6wQemQsy27oMAhHjYEMJT64zLN77h3EUeXxadG/W5OcrSoeuWVgYdjmPGQCp4lu3cUgkA6ZwhDDl5xZrEdIjG4/9zXylBUbxbylTsZllVOkd9ZRA9SODPtdm+rrc7QldBeTmdCtDfTkrP8qZr+7D114Smr8LatNiA9wl04xVgIz4w== rsa-key-20171223

unrar and use this private key in putty to log in
username is root as always

to load key into putty go to:
Category: Connection>SSH>Auth > on the right side click Browse and choose your key



test key.rar
 Description:

Download
 Filename:  test key.rar
 Filesize:  1.21 KB
 Downloaded:  229 Time(s)


_________________
Atheros
TP-Link WR740Nv1 ---DD-WRT 55630 WAP
TP-Link WR1043NDv2 -DD-WRT 55723 Gateway/DoT,Forced DNS,Ad-Block,Firewall,x4VLAN,VPN
TP-Link WR1043NDv2 -Gargoyle OS 1.15.x AP,DNS,QoS,Quotas
Qualcomm-Atheros
Netgear XR500 --DD-WRT 55779 Gateway/DoH,Forced DNS,AP Isolation,4VLAN,Ad-Block,Firewall,Vanilla
Netgear R7800 --DD-WRT 55819 Gateway/DoT,AD-Block,Forced DNS,AP&Net Isolation,x3VLAN,Firewall,Vanilla
Netgear R9000 --DD-WRT 55779 Gateway/DoT,AD-Block,AP Isolation,Firewall,Forced DNS,x2VLAN,Vanilla
Broadcom
Netgear R7000 --DD-WRT 55460 Gateway/SmartDNS/DoH,AD-Block,Firewall,Forced DNS,x3VLAN,VPN
NOT USING 5Ghz ANYWHERE
------------------------------------------------------
Stubby DNS over TLS I DNSCrypt v2 by mac913


Last edited by Alozaros on Sat Dec 23, 2017 16:37; edited 1 time in total
hatcreek68
DD-WRT Novice


Joined: 29 Nov 2016
Posts: 27

PostPosted: Sat Dec 23, 2017 12:33    Post subject: Reply with quote
Alozaros wrote:
nope its not like that....🌝


If it works, it's kinda like that. Maybe I stated it wrong. I assumed I could use my web gui username, forgot ssh only works with root. Whereas something like my raspberry pi you can ssh as any user.

Copy paste the public key from the puttygen window has the format you show and it works.

Save, reference the private key to login.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum