SSH public key authentication: Difference between revisions
m Make keyFiles suggestion compatible with pure evaluation mode Tags: Mobile edit Mobile web edit Visual edit |
m indentation and style improvements |
||
| Line 24: | Line 24: | ||
To make the SSH client automatically use the key file, add a host entry to your per-user SSH configuration file: | To make the SSH client automatically use the key file, add a host entry to your per-user SSH configuration file: | ||
{{file|~/.ssh/config| | {{file|~/.ssh/config|nix| | ||
<nowiki> | <nowiki> | ||
Host another-machine | Host another-machine | ||
| Line 66: | Line 66: | ||
{{file|/etc/nixos/configuration.nix|nix| | {{file|/etc/nixos/configuration.nix|nix| | ||
<nowiki> | <nowiki> | ||
users.users."myUser".openssh.authorizedKeys.keys = [ | |||
"ssh-rsa AAAAB3Nz....6OWM= user" # content of authorized_keys file | |||
# note: ssh-copy-id will add user@your-machine after the public key | |||
# but we can remove the "@your-machine" part | |||
]; | |||
</nowiki> | </nowiki> | ||
}} | }} | ||
| Line 78: | Line 78: | ||
{{file||| | {{file||| | ||
<nowiki> | <nowiki> | ||
users.users."user".openssh.authorizedKeys.keyFiles = [ | |||
./ssh/authorized_keys | |||
]; | |||
</nowiki> | </nowiki> | ||
|name=/etc/nixos/configuration.nix|lang=nix}} | |name=/etc/nixos/configuration.nix|lang=nix}} | ||
| Line 92: | Line 92: | ||
{{file|/etc/nixos/configuration.nix|nix| | {{file|/etc/nixos/configuration.nix|nix| | ||
<nowiki> | <nowiki> | ||
services.openssh = { | |||
enable = true; | |||
# require public key authentication for better security | |||
settings.PasswordAuthentication = false; | |||
settings.KbdInteractiveAuthentication = false; | |||
}; | }; | ||
</nowiki> | </nowiki> | ||