ssh keys for NX-OS to access SFTP

Enabling contained, passwordless sftp from NX-OS switches to a Linux server

Note: This post is barely note-to-self grade documentation. Pulled together long after originally implemented, it may be missing necessary commands or information. Hopefully this is enough to be able to reproduce the concepts if ever useful elsewhere, but not likely to work as-is without experimentation, research, and validation.

Goal

Allow switches to push (e.g. config backups, à la tftp, but with connection security) and pull (e.g. OS image files) to and from a linux server.

Notable characteristics of this solution

  • Makes use of standard linux ugo permission heirarchy
  • Switches use ssh public key authentication for sftp connnections
  • Ssh daemon configuration and linux group membership allows switches to:
    • Read and write from a common directory
    • Have all their public keys in a single file on the server
      • not each switch with its own ~/.ssh/authorized_keys
        • Which in turn means no need for unique home directories
    • Only have sftp access on connecting via ssh
    • Have sftp access contained to a specific folder with chroot
  • SSH keys are only valid from predetermined ip addresses, further reducing risk in case of compromise
  • SELinux was not in play here. SELinux may require additional attention to reproduce this on Enterprise Linux servers
  • There is probably room for improvement

Nexus config

Generate rsa keypair for default admin user

username admin keypair generate rsa 2048


Collect public key for admin user

show username admin keypair | include ssh-rsa

Reference

Cisco Nexus 9000 Series NX-OS Security Configuration Guide, Release 7.x #Configuration Example for SSH  

There were a number of great blogs that I pulled bits from to arrive at this solution (especially around the ssh configuration), and I wish I had those links at hand to give them the due credit.

Sftp server config

mkdir /sftp
chown root:root /sftp
chmod 701 /sftp
mkdir /sftp/nexus
addgroup networkdevices
adduser --disabled-password --ingroup networkdevices --home /nexus --no-create-home --gecos nexus1 –shell '' nexus1
chown root:networkdevices /sftp/nexus
chmod 570 /sftp/nexus
sudo -u nexus1 touch /sftp/nexus/nexus1-confg
chmod 600 /sftp/nexus/nexus1-confg
 

/etc/ssh/sshd_config
Subsystem sftp /usr/lib/openssh/sftp-server

# Added
LogLevel VERBOSE
Match Group networkdevices
        PasswordAuthentication no
        AuthorizedKeysFile /etc/ssh/sshd_config.keys/networkdevices
        ForceCommand internal-sftp
        ChrootDirectory /sftp

/etc/ssh/sshd_config.keys/networkdevices
# nexus1, assuming 192.0.2.0/24 is our oob management network
from="192.0.2.1" ssh-rsa AAAAB…
# nexus2
from="192.0.2.2" ssh-rsa AAAAB…
# nexus3, assuming nexus3 uses both oob and inband 198.51.100.0/24
from="192.0.2.3,198.51.100.1" ssh-rsa AAAAB…

 

Comments

Popular posts from this blog

On starting a blog

Grow LVM Thin Volume