Linux Password Less Authentication (rsa key file): Difference between revisions

From PedrosBrainDump
Created page with "=== '''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 * <code>-t rsa</code>: Specifies the RSA algorithm (you can also use <code>ed25519</code> for better security). * <code>-b 4096</code>: Sets the key size (4096 bits for RSA). * <code>-f ~/.ssh/username</code>: This option lets you set the filename and path for the key. Here, it will save the private key as <code>~/.ssh/username<..."
 
No edit summary
 
Line 1: Line 1:
=== '''Generate the SSH key pair on your local machine''' (the one you want to connect from): ===
# Create key pair
  ssh-keygen -t rsa -b 4096 -f ~/.ssh/username
  ssh-keygen -t rsa -b 4096 -f ~/.ssh/username
 
* <code>-t rsa</code>: Specifies the RSA algorithm (you can also use <code>ed25519</code> for better security).
# Add the public key to the `authorized_keys` file
* <code>-b 4096</code>: Sets the key size (4096 bits for RSA).
cat ~/.ssh/username.pub >> ~/.ssh/authorized_keys
* <code>-f ~/.ssh/username</code>: This option lets you set the filename and path for the key. Here, it will save the private key as <code>~/.ssh/username</code> and the public key as <code>~/.ssh/username.pub</code>.
 
chmod 700 ~/.ssh             # Set the directory permissions
=== '''Save the key files''': ===
  chmod 600 ~/.ssh/authorized_keys # Set the file permissions
 
* You’ll be prompted to choose a file location for the keys. Press <code>Enter</code> to accept the default path (<code>~/.ssh/id_rsa</code>).
* You’ll then be asked to set a passphrase. Press <code>Enter</code> 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

Latest revision as of 16:50, 7 November 2024

# Create key pair
ssh-keygen -t rsa -b 4096 -f ~/.ssh/username

# Add the public key to the `authorized_keys` file
cat ~/.ssh/username.pub >> ~/.ssh/authorized_keys

chmod 700 ~/.ssh             # Set the directory permissions
chmod 600 ~/.ssh/authorized_keys  # Set the file permissions