Generate the SSH key pair on your local machine (the one you want to connect from):
ssh-keygen -t rsa -b 4096 -f ~/.ssh/username
-t rsa
: Specifies the RSA algorithm (you can also use ed25519
for better security).
-b 4096
: Sets the key size (4096 bits for RSA).
-f ~/.ssh/username
: This option lets you set the filename and path for the key. Here, it will save the private key as ~/.ssh/username
and the public key as ~/.ssh/username.pub
.
Save the key files:
- You’ll be prompted to choose a file location for the keys. Press
Enter
to accept the default path (~/.ssh/id_rsa
).
- You’ll then be asked to set a passphrase. Press
Enter
if you want passwordless login; otherwise, enter a passphrase for extra security.
you can manually copy the key:
scp ~/.ssh/username.pub username@server_ip_address:/home/username/.ssh/authorized_keys