Laravel Forge is a powerful tool for managing and deploying your PHP web applications. One crucial aspect of managing your server on Forge is adding SSH keys for secure access. In this step-by-step guide, we’ll walk you through the process of adding an SSH key to Laravel Forge, ensuring that your server remains secure and accessible.
Prerequisites
Before you begin, make sure you have the following:
- A Laravel Forge Account: You need an active Laravel Forge account to access your server and manage SSH keys.
- SSH Key Pair: If you don’t have an SSH key pair, generate one using the following command on your local machine:
ssh-keygen -t rsa -b 4096
- This command will generate a public key (
id_rsa.pub
) and a private key (id_rsa
). Keep your private key secure and never share it.
Step 1: Log in to Laravel Forge
- Open your web browser and navigate to Laraval Forge.
- Sign in with your Laravel Forge credentials.
Step 2: Access Your Server
- Once logged in, click on the “Servers” tab in the Forge dashboard.
- Select the server to which you want to add the SSH key. If you haven’t set up a server yet, follow the Forge documentation to create one.
Step 3: Navigate to the Server’s SSH Keys
- In the server management interface, click on the “SSH Keys” tab on the left-hand sidebar.
Step 4: Add a New SSH Key
- To add a new SSH key, click the “+ New SSH Key” button.
- In the “Name” field, give your SSH key a recognizable name. This is useful if you have multiple keys.
- In the “Key” field, paste the contents of your public key (
id_rsa.pub
) that you generated earlier. - Click the “Add SSH Key” button to save your new key.
Step 5: Verify SSH Key Addition
- After adding the key, you should see it listed in the “SSH Keys” section for your server.
- You can now use this SSH key to access your server securely.
Step 6: Access Your Server via SSH
- To access your server via SSH using the added key, open your terminal.
- Use the following command, replacing
<your_server_ip>
with your server’s IP address
ssh forge@<your_server_ip>
3. You will be prompted to enter the passphrase for your SSH key (if you set one during key generation). Once entered, you’ll have secure access to your server.
Managing SSH keys is a fundamental aspect of securing your server infrastructure. With this step-by-step guide, you can easily add an SSH key to Laravel Forge and ensure secure, convenient access to your servers. Remember to keep your private key safe and never share it with unauthorized individuals.