SSH: Difference between revisions
Create ssh page, detail server and client configuration |
m →Configuration: use indented string for programs.ssh.extraConfig |
||
| (7 intermediate revisions by 7 users not shown) | |||
| Line 10: | Line 10: | ||
Take the time to comprehend the implications of your actions and ensure that any changes made are done thoughtfully and with care.}} | Take the time to comprehend the implications of your actions and ensure that any changes made are done thoughtfully and with care.}} | ||
= | == Server == | ||
=== Setup === | |||
To enable a SSH service, add the following to your system configuration: | To enable a SSH service, add the following to your system configuration: | ||
{{file|/etc/nixos/configuration.nix|nix| | {{file|/etc/nixos/configuration.nix|nix| | ||
<nowiki> | <nowiki> | ||
services.openssh = { | |||
enable = true; | |||
openFirewall = true; | |||
settings = { | |||
PasswordAuthentication = false; | |||
KbdInteractiveAuthentication = false; | |||
PermitRootLogin = "no"; | |||
AllowUsers = [ "myUser" ]; | |||
MaxAuthTries = 3; | |||
PerSourcePenalties = "crash:3600s authfail:3600s max:86400s"; | |||
}; | }; | ||
}; | |||
</nowiki> | </nowiki> | ||
}} | |name=/etc/nixos/configuration.nix|lang=nix}} | ||
By default, the server listens on port 22 | The example restricts authentication only to the user defined in <code>settings.AllowUsers</code> by using [[SSH public key authentication|public key authentication]]. By default, the server listens on port 22. For further security, the default listenig port should be changed using the <code>ports</code> option. | ||
For more SSH server configuration options, refer to the {{nixos:option|services.openssh}} module options. | For more SSH server configuration options, refer to the {{nixos:option|services.openssh}} module options. | ||
== | == Client == | ||
=== Configuration === | |||
The OpenSSH client is available by default on NixOS and can be configured using the {{nixos:option|programs.ssh}} module options. | The OpenSSH client is available by default on NixOS and can be configured using the {{nixos:option|programs.ssh}} module options. | ||
{{file|/etc/nixos/configuration.nix|nix| | {{file|/etc/nixos/configuration.nix|nix| | ||
<nowiki> | <nowiki> | ||
programs.ssh = { | |||
extraConfig = '' | |||
Host myhost | |||
Hostname 192.168.1.123 | |||
Port 22 | |||
User user | |||
''; | |||
}; | |||
</nowiki> | </nowiki> | ||
}} | }} | ||
| Line 85: | Line 65: | ||
Alternatively, you can manually manage SSH client configuration by placing entries in the user-specific <code>~/.ssh/config</code> file. | Alternatively, you can manually manage SSH client configuration by placing entries in the user-specific <code>~/.ssh/config</code> file. | ||
[[Category:Networking]] | [[Category:Networking]] | ||
[[Category:Server]] | [[Category:Server]] | ||