Difference between revisions of "Enabling SSH Logins To The UDM"

From Nearline Storage
Jump to navigation Jump to search
m
m
Line 22: Line 22:
 
Copy the [https://github.com/boostchicken/udm-utilities/blob/master/on-boot-script/examples/udm-files/on_boot.d/15-add-root-ssh-key.sh 15-add-root-ssh-key.sh] file to <code>/mnt/data/on-boot.d/</code> and put the public SSH key into it.  Either run that script manually, or reboot the UDM to populate the <code>/root/.ssh/authorized_keys</code> file with the SSH key.
 
Copy the [https://github.com/boostchicken/udm-utilities/blob/master/on-boot-script/examples/udm-files/on_boot.d/15-add-root-ssh-key.sh 15-add-root-ssh-key.sh] file to <code>/mnt/data/on-boot.d/</code> and put the public SSH key into it.  Either run that script manually, or reboot the UDM to populate the <code>/root/.ssh/authorized_keys</code> file with the SSH key.
  
Logons from the client using the default SSH configuration will still prompt for a password.  This is due to a mismatch in the encryption methods that the SSH server and client are setup to use.  To fix this, add a stanza to the <code>~/.ssh/config</code> file on the client, setting ''udm-hostname'' to be the host name or IP address that you use with the ssh command:
+
Logons from the client using the default SSH configuration may still prompt for a password.  If they do, this is due to a mismatch in the encryption methods that the SSH server and client are setup to use.  To fix this, add a stanza to the <code>~/.ssh/config</code> file on the client, with ''udm-hostname'' set to the host name or IP address that is used with the ssh command:
 
     Host ''udm-hostname''
 
     Host ''udm-hostname''
 
         User root
 
         User root
 
         PubkeyAcceptedKeyTypes +ssh-rsa
 
         PubkeyAcceptedKeyTypes +ssh-rsa

Revision as of 13:55, 19 January 2021

SSH In The Admin UI

The UDM has two different SSH configurations, one that allows login to the UDM itself and another that the UDM provisions onto the other UniFi network devices it adopts so that you can directly login to them.

The one that allows logins to the UDM itself only supports userid/password authentication out of the box. We want to add public key authentication to that so that we don't have to enter a password every time we log in. But first we must enable the SSH service through the admin UI:

  1. Click through "Settings" -> "Advanced" from the bottom of the main UI window
  2. Turn on "SSH" and set a password. SSH login for the "root" user is now possible by entering a password.

The other SSH configuration that the UDM uses to provision other UniFi devices on the network is set up, using the "New Settings" menus, under "Network" -> "Settings" -> "System Settings" -> "Controller Configuration" -> "Device SSH Authentication". A userid, password and SSL keys can be setup here. These will be provisioned to each UniFi networking device on the network that this controller adopts.

Setting A Persistent SSH Key For The root User

Setting the login key requires that we add our SSH key to the /root/.ssh/authorized_keys file. The trouble is that this file gets wiped and restored every time the UDM reboots, causing it to lose the changes we make. We will use the on-boot-script utility from the udm-utilities package on GitHub to overcome this issue. It will restore our SSH key to the /root/.ssh/authorized_keys each time the UDM reboots.

As root on the UDM do:

   # unifi-os shell
   # curl -L https://raw.githubusercontent.com/boostchicken/udm-utilities/master/on-boot-script/packages/udm-boot_1.0.2_all.deb -o udm-boot_1.0.2_all.deb
   # dpkg -i udm-boot_1.0.2_all.deb
   # exit

Copy the 15-add-root-ssh-key.sh file to /mnt/data/on-boot.d/ and put the public SSH key into it. Either run that script manually, or reboot the UDM to populate the /root/.ssh/authorized_keys file with the SSH key.

Logons from the client using the default SSH configuration may still prompt for a password. If they do, this is due to a mismatch in the encryption methods that the SSH server and client are setup to use. To fix this, add a stanza to the ~/.ssh/config file on the client, with udm-hostname set to the host name or IP address that is used with the ssh command:

   Host udm-hostname
       User root
       PubkeyAcceptedKeyTypes +ssh-rsa