This tutorial guides you through installing OpenSSH on NixOS, highlighting the differences from traditional Linux distributions.
Table of Contents
Introduction
Unlike Debian or RHEL, NixOS utilizes a declarative and atomic package management system. Instead of directly installing packages, NixOS builds a new system configuration, ensuring reproducibility and enabling atomic upgrades and rollbacks. This approach avoids dependency conflicts and promotes a declarative configuration via /etc/nixos/configuration.nix
.
Installing OpenSSH on NixOS
Edit /etc/nixos/configuration.nix
using a text editor (e.g., sudo nano /etc/nixos/configuration.nix
).
Uncomment or add the following line to enable the OpenSSH daemon:
services.openssh.enable = true;
Optional customizations:
# services.openssh.permitRootLogin = "no"; # services.openssh.passwordAuthentication = true; # services.openssh.port = 22; # services.openssh.protocol = "2";
Remember to uncomment your chosen settings.
Save and exit the editor.
Rebuild the NixOS system: sudo nixos-rebuild switch
After the rebuild, OpenSSH should be running. Verify with: sudo systemctl sshd status
Connect via SSH using an SSH client (e.g., ssh username@ip_address
).
Verifying NixOS Version
Confirm your NixOS installation by checking the version: nixos-version
This displays the release version, codename, and Git revision.
Conclusion
This tutorial detailed OpenSSH installation on NixOS. While initially more complex, NixOS's method offers significant benefits in system reliability and integrity.
Further Reading:
The above is the detailed content of How To Install openSSH on NixOS. For more information, please follow other related articles on the PHP Chinese website!