Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
engineering:computer_science:linux:hardening:linux_passwordless_ssh_login [2024/08/16 13:56] – removed - external edit (Unknown date) 127.0.0.1 | engineering:computer_science:linux:hardening:linux_passwordless_ssh_login [2024/08/16 13:56] (current) – ↷ Links adapted because of a move operation carlossousa | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Linux: Configuring Passwordless Login via SSH ====== | ||
+ | |||
+ | Also Part of: [[engineering: | ||
+ | |||
+ | ===== Summary of Steps: ===== | ||
+ | |||
+ | - Make Public / Private Key Pair | ||
+ | - Add Public Key to Server | ||
+ | - Verify Passwordless Login Works | ||
+ | - Disable Password Login on Server | ||
+ | |||
+ | ===== Guide ===== | ||
+ | |||
+ | ==== Generating Public / Private Key Pair ==== | ||
+ | |||
+ | <code bash> | ||
+ | ssh-keygen -t rsa | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Add Public Key to Server ==== | ||
+ | |||
+ | === Manual Way === | ||
+ | |||
+ | Go to .ssh under your home directory | ||
+ | |||
+ | <code bash> | ||
+ | cd ~/.ssh | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | Info: In case you don't have a " | ||
+ | |||
+ | <code bash> | ||
+ | mkdir .ssh && sudo chmod 700 .ssh | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | Inside you should have a file called " | ||
+ | |||
+ | <code bash> | ||
+ | touch authorized_keys && sudo chmod 600 authorized_keys | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | Copy your public key from *.pub to authorized_keys. It should look something like this: | ||
+ | |||
+ | <code bash> | ||
+ | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVtv5prVJ[.....] | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | === Automatic / Easy Way === | ||
+ | |||
+ | <code bash> | ||
+ | ssh-copy-id user@remote-host | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Verify that the Passwordless Login Works ==== | ||
+ | |||
+ | ==== Disable Login via Password ==== | ||
+ | |||
+ | __**Important!**__ | ||
+ | |||
+ | Edit the file " | ||
+ | |||
+ | <code bash> | ||
+ | nano / | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | Update / Confirm the following 3 values: | ||
+ | |||
+ | <code bash> | ||
+ | PasswordAuthentication no | ||
+ | ChallengeResponseAuthentication no | ||
+ | UsePAM no | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | Restart the service with: | ||
+ | |||
+ | <code bash> | ||
+ | sudo systemctl restart sshd | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Using per-host SSH configuration ====== | ||
+ | |||
+ | ===== Edit your .ssh/config ===== | ||
+ | |||
+ | < | ||
+ | sudo nano ~/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ~/ | ||
+ | |||
+ | < | ||
+ | HostName 10.20.30.40 | ||
+ | User remoteUser | ||
+ | IdentityFile ~/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | Connect with: | ||
+ | |||
+ | < | ||
+ | ssh opportunity | ||
+ | |||
+ | </ | ||