Skip to content
Davood Dorostkar edited this page Dec 23, 2023 · 5 revisions

Basics

when you make a key, you will have a private key (without extension) and a public key (*.pub). you need to give your public key to the host system to enable ssh connection. your public key will be stored in ~/.ssh/authorized_keys in the host system. whenever you make a connection, the host's public key will be also stored in ~/.ssh/known_hosts for future to prevent man-in-the-middle.

Make keys

make a key pair

ssh-keygen -t <algorithm>

make a pair in specific dir

ssh-keygen -t <algorithm> -f <path>

make key with custom comment; comment is by default like davood@davood-pc:

ssh-keygen -C

change existing key comment:

ssh-keygen -c

Default paths

in debian: ~/.ssh/

in windows: /c/Users/<USER>/.ssh/

Copy keys to host

this will add your public key to ~/.ssh/authorized_keys in the host system.

ssh-copy-id -i <path_to_pub_key> <user>@<IP_address>

Enable Password login

be default login to root with password is disabled in many cases for security. (even if you have set a password for it). to enable it:

  1. set a password:
passwd
  1. enable password authentication in /etc/ssh/sshd_config:
PasswordAuthentication yes
  1. enable root login:
PermitRootLogin yes
  1. restart ssh service:
service ssh restart
Clone this wiki locally