To connect to a production server via SSH, you will need to generate an SSH key pair. The private key will be stored on your local machine, and the public key will be added to the server's authorized keys file.
To generate an SSH key pair, follow these steps:
- Open your terminal or command prompt.
- Type
ssh-keygenand press enter. - You will be prompted to enter a file name for the key pair. The default is
id_rsa, but you can choose a different name if you prefer. - You will also be prompted to enter a passphrase. This is optional, but recommended for added security.
- Once the key pair is generated, you can find the private key in
~/.ssh/on your local machine. The public key will be in a file with the same name as the private key, but with a.pubextension.
To upload the public key to the server, you can use the ssh-copy-id command. Here's an example:
ssh-copy-id user@server
Replace user with your username on the server, and server with the hostname or IP address of the server. You will be prompted to enter your password for the server. Once you enter it, the public key will be added to the server's authorized keys file.
After that, you should be able to connect to the server via SSH without entering a password. Here's an example:
ssh user@server
Again, replace user and server with your own values.
I hope this helps! Let me know if you have any questions.