Skip to main content
added 17 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9

HOW TO REPLACE SSH HOST KEYS ON RASPBIAN W/O BOOTING INTO IT

HOW TO REPLACE SSH HOST KEYS ON RASPBIAN W/O BOOTING INTO IT

PROCEDURE

HOW TO REPLACE SSH HOST KEYS ON RASPBIAN W/O BOOTING INTO IT

HOW TO REPLACE SSH HOST KEYS ON RASPBIAN W/O BOOTING INTO IT

PROCEDURE

added 152 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9

If your ssh "connection refused" error is due to a problem with the Raspbian host's ssh keys (and one way to find out is to update them), you can replace them without booting into Raspbian if you have access to a running Linux host, which I will call a "helper" host. (Note: I went this route because there aren't safe/supported solutions I could find for mounting Linux ext4 partitions in 'writable' mode on macOS).

Your Linux helper host could be Raspbian running on another Pi, Linux running on PC hardware, or if you only have a Windows or Mac host, it could be guest virtual machine running Linux with VirtualBox, etc... Assuming

Assuming you have a way to mount the Raspbian media on that host, it's easy to reconfigure the SSH keys by simply overwriting them, because virtually all Linux distributions, (including Raspbian), have openssh installed, which offers the same set of tools.

HOW TO REPLACE SSH HOST KEYS ON RASPBIAN WITHOUTW/O BOOTING INTO IT

If your ssh "connection refused" error is due to a problem with the Raspbian host's ssh keys (and one way to find out is to update them), you can replace them without booting into Raspbian if you have access to a running Linux host, which I will call a "helper" host.

Your Linux helper host could be Raspbian running on another Pi, Linux running on PC hardware, or if you only have a Windows or Mac host, it could be guest virtual machine running Linux with VirtualBox, etc... Assuming you have a way to mount the Raspbian media on that host, it's easy to reconfigure the SSH keys by simply overwriting them, because virtually all Linux distributions, (including Raspbian), have openssh installed, which offers the same set of tools.

HOW TO REPLACE SSH HOST KEYS ON RASPBIAN WITHOUT BOOTING INTO IT

If your ssh "connection refused" error is due to a problem with the Raspbian host's ssh keys (and one way to find out is to update them), you can replace them without booting into Raspbian if you have access to a running Linux host, which I will call a "helper" host. (Note: I went this route because there aren't safe/supported solutions I could find for mounting Linux ext4 partitions in 'writable' mode on macOS).

Your Linux helper host could be Raspbian running on another Pi, Linux running on PC hardware, or if you only have a Windows or Mac host, it could be guest virtual machine running Linux with VirtualBox, etc...

Assuming you have a way to mount the Raspbian media on that host, it's easy to reconfigure the SSH keys by simply overwriting them, because virtually all Linux distributions, (including Raspbian), have openssh installed, which offers the same set of tools.

HOW TO REPLACE SSH HOST KEYS ON RASPBIAN W/O BOOTING INTO IT

added 245 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
  1. Mount the Linux partition, as follows (we'll assume the device is /dev/sb2 and the mount point is /mnt through the rest of the example).

    Note: Your actual device and chosen mount point may be different and you'll have to adjust this procedure accordingly.

     $ sudo mount /dev/sb2 /mnt
    
  2. Now you can generate new keys to replace the old keys in your micro SD's (Raspbian OS) ssh directory:

     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_rsa_key -N '' -t rsa 
     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_dsa_key -N '' -t dsa
     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521
    
  3. Now eject the micro SD card, so you can safely physically remove it:

     $ sudo eject /mnt  
    

    Note: Eject will fail if any terminal windows are still cd'd into any Raspbian partition directories, so either close any such windows or cd to a different directory.

  4. Re-insert the micro SD into the pi and try booting. Hopefully the ssh connection refused problem will be gone. Of course there are any number of ways ssh might not be working - not installed, out of date, misconfigured, not starting, etc...

  1. Mount the Linux partition, as follows (we'll assume the device is /dev/sb2 and the mount point is /mnt through the rest of the example).

    Note: Your actual device and chosen mount point may be different and you'll have to adjust this procedure accordingly.

     $ sudo mount /dev/sb2 /mnt
    
  2. Now you can generate new keys to replace the old keys in your micro SD's (Raspbian OS) ssh directory:

     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_rsa_key -N '' -t rsa 
     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_dsa_key -N '' -t dsa
     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521
    
  3. Now eject the micro SD card, so you can safely physically remove it:

     $ sudo eject /mnt  
    

    Note: Eject will fail if any terminal windows are still cd'd into any Raspbian partition directories, so either close any such windows or cd to a different directory.

  1. Mount the Linux partition, as follows (we'll assume the device is /dev/sb2 and the mount point is /mnt through the rest of the example).

    Note: Your actual device and chosen mount point may be different and you'll have to adjust this procedure accordingly.

     $ sudo mount /dev/sb2 /mnt
    
  2. Now you can generate new keys to replace the old keys in your micro SD's (Raspbian OS) ssh directory:

     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_rsa_key -N '' -t rsa 
     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_dsa_key -N '' -t dsa
     $ sudo ssh-keygen -f /mnt/etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521
    
  3. Now eject the micro SD card, so you can safely physically remove it:

     $ sudo eject /mnt  
    

    Note: Eject will fail if any terminal windows are still cd'd into any Raspbian partition directories, so either close any such windows or cd to a different directory.

  4. Re-insert the micro SD into the pi and try booting. Hopefully the ssh connection refused problem will be gone. Of course there are any number of ways ssh might not be working - not installed, out of date, misconfigured, not starting, etc...

added 282 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
Typos of Raspbian; formatting consistency
Source Link
Aurora0001
  • 6.3k
  • 3
  • 25
  • 39
Loading
added 10 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
added 234 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
added 30 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
added 136 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
added 157 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
added 4 characters in body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
edited body
Source Link
clearlight
  • 259
  • 2
  • 9
Loading
Source Link
clearlight
  • 259
  • 2
  • 9
Loading