Using ssh-copy-id & ssh-keygen Commands in Linux
Secure Shell (SSH) is a crucial tool for securely connecting to remote systems. To improve security and ease of access, SSH key authentication is often preferred over password authentication. Two important commands in this process are ssh-keygen and ssh-copy-id.
The ssh-keygen command is used to generate SSH key pairs. To create a new key pair, run the following command in Linux environment:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
After running the command, you will be prompted to specify a file to save the key (default: ~/.ssh/id_rsa) and an optional passphrase for added security.
Once the key pair is generated, you need to transfer the public key to the remote server. The ssh-copy-id command simplifies this process:
ssh-copy-id user@remote-server
This command appends your public key (id_rsa.pub) to the ~/.ssh/authorized_keys file on the remote machine, enabling passwordless authentication.
To check if key-based authentication is working, try connecting to the remote server:
ssh user@remote-server
If everything is set up correctly, you should be logged in without needing a password.
Using ssh-keygen and ssh-copy-id enhances security and convenience when managing remote servers. By configuring SSH key authentication, administrators can eliminate the risks associated with password-based logins while streamlining secure access.