King Zone - ssh-keygen
type: channel
link: https://www.kingtam.win/tag/ssh-keygen/
items: Secure Linux Login Connection

Secure Linux Login Connection
type: item
date: 2023-07-26T08:18:00+08:00
description: Secure Linux Login Connectionssh-key.jpgIntroductionSSH offers two methods of authentication: password and key pair authentication.Password Authentication: While simple passwords are easily remembered, they are also easily compromised through brute force attacks. On the other hand, complex passwords, though safer, are challenging to remember.Key Pair Authentication: This method involves a combination of a public key and a private key. The public key is placed on the device that one wishes to access, while the private key is stored on the user's local machine. Only the holder of the private key can access the device, making this method secure and convenient.Generating a Key Pair with ssh-keygenThe ssh-keygen command can be used to generate a key pair. Here is how to use it:ssh-keygenFor a stronger key pair, use:ssh-keygen -t rsa -b 4096 -C $commentNote: When prompted, hit Enter for each prompt.Uploading the Public Key to the Remote HostThere are two ways to upload the public key: manually and automatically.Automatic UploadTo automatically upload the public key, run:ssh-copy-id user@remoteHostOr specify the public key and port:ssh-copy-id -i ~/.ssh/id_rsa.pub user@remoteHostManual UploadTo manually upload the public key, copy the public key content:ssh user@remoteHost 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pubNext, set the correct permissions on the remote host:chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keysAfter creating the authorized_keys file and pasting the public key contents into it, we can log in without a password:ssh user@remoteHostManaging Sessions via SSH ProfilesSSH profiles are an elegant and efficient way to manage multiple remote logins. You can create several remote hosts on the SSH profiles as shown:cat >> ~/.ssh/config << EOF Host HOST01 HostName 123.123.123.33 Port 22 User user01 IdentityFile "~/.ssh/id_rsa" IdentitiesOnly yes Host HOST02 HostName 10.110.254.99 Port 2222 User user02 IdentityFile "~/.ssh/id_ecdsa" Identitie…