How to Add an SSH Key to Laravel Forge: Easy Step-by-Step Guide

Table of Contents

Adding an SSH key to Laravel Forge allows you to securely access and manage your server. SSH key authentication provides a secure alternative to password-based authentication and is commonly used for server administration, application deployment, and infrastructure management.

For businesses running production applications, properly managing SSH access is important for protecting server resources, maintaining security, and avoiding deployment interruptions. As infrastructure grows, managing server access and security across multiple users and servers can become increasingly challenging.

In this guide, you’ll learn how to add an SSH key to Laravel Forge, manage secure server access, and identify common SSH connection issues.

How to Add an SSH Key to Laravel Forge

To add an SSH key to Laravel Forge:

  1. Generate an SSH key pair on your local computer.

  2. Copy the public key, usually stored in a .pub file.

  3. Log in to Laravel Forge and open the appropriate SSH Keys section.

  4. Add the public key to your account or server, depending on your requirements.

  5. Verify that the key is installed and that SSH authentication is working.

Security tip: Never share your private SSH key. Only the public key should be added to Laravel Forge.

Step 1: Generate an SSH Key Pair

If you don’t already have an SSH key pair, generate one on your local computer.

For systems that support Ed25519, open your terminal and run:

ssh-keygen -t ed25519 -C "[email protected]"

Follow the prompts to choose where to save the key and whether to protect it with a passphrase.

If your environment does not support Ed25519, RSA 4096 is an alternative:

ssh-keygen -t rsa -b 4096

The generated files typically include:

  • Private key: id_ed25519 or id_rsa

  • Public key: id_ed25519.pub or id_rsa.pub

The public key is the one you will add to Laravel Forge. Keep your private key secure and never upload or share it.

Step 2: Log In to Laravel Forge

Open Laravel Forge and sign in using your account credentials.

Once logged in, locate the server you want to access. Make sure you select the correct server before modifying its SSH access settings.

Step 3: Open the SSH Keys Section

Laravel Forge provides options for managing SSH keys at the account and server levels. The appropriate option depends on how you want to manage access.

  • Server-level SSH key: Useful when you want to configure access for a particular server.

  • Account-level SSH key: Useful when you want to manage a key centrally and use it with supported servers.

Open the relevant SSH Keys section in the current Forge dashboard. The exact interface and available options may vary, so refer to the official Laravel Forge documentation if the menu labels differ.

Step 4: Add Your Public SSH Key

Once you’ve opened the appropriate SSH Keys section:

  1. Select the option to add a new SSH key.

  2. Enter a recognizable name, such as Work Laptop.

  3. Open your public key file, for example id_ed25519.pub.

  4. Copy its contents and paste them into the public key field.

  5. Save the key and confirm that it appears in the SSH Keys list.

Make sure you copy the entire public key, including its key type and encoded content.

Important: Do not paste the private key file into Laravel Forge. Sharing your private key can compromise your server access.

Step 5: Verify the SSH Key

After adding the key, confirm that it appears in the relevant SSH Keys list and that Forge has completed the key installation for the intended server user.

Open your terminal and run:

ssh forge@YOUR_SERVER_IP

Replace YOUR_SERVER_IP with your server’s public IP address.

If you have saved your private key in a non-default location, you may need to specify it using the -i option:

ssh -i ~/.ssh/id_ed25519 forge@YOUR_SERVER_IP

If your private key has a passphrase, you may be prompted to enter it. Successful authentication confirms that SSH access is working for the specified user.

If the connection fails, the issue may be related to your username, server IP, key configuration, firewall rules, or SSH port.

For businesses managing multiple production servers, regularly reviewing SSH access and user permissions is important for maintaining infrastructure security.

Step 6: Troubleshoot Common SSH Connection Issues

Even after adding an SSH key, you may encounter connection problems. Understanding the error message can help identify the cause.

Permission Denied (Publickey)

This error usually indicates that the server could not authenticate using the offered SSH key.

Possible causes include:

  • The wrong public key was added.

  • The corresponding private key is unavailable to the SSH client.

  • The key has not been installed for the intended server user.

  • The SSH client is using a different key than expected.

Verify the key configuration in Forge and confirm that you’re connecting with the correct user.

Connection Timed Out

A timeout can indicate a network connectivity problem or that SSH traffic is being blocked.

Check the server IP address, firewall rules, network access, and configured SSH port.

Connection Refused

This error may indicate that the SSH service is not listening on the expected port or that a firewall or server configuration is rejecting the connection.

Review the server’s SSH service and network configuration before making changes.

For related connection problems, see our guide on troubleshooting SFTP connection refused errors.

SSH Key Added but Access Still Fails

Confirm that the key has been installed on the intended server and that the correct SSH user is being used. If the problem persists, the issue may require further investigation of server authentication settings and permissions.

For additional protection, explore these Linux server security best practices.

For businesses experiencing persistent SSH authentication or connectivity issues, professional server management support can help identify underlying configuration and security problems.

Conclusion

Adding an SSH key to Laravel Forge helps simplify server access while supporting secure authentication. Understanding SSH key management, server access permissions, and common connection issues is important for maintaining a reliable server environment.

However, SSH access is only one part of maintaining secure and reliable production infrastructure. Regular monitoring, server maintenance, security updates, and access control are equally important.

If your business needs help managing server access, maintaining infrastructure security, or resolving server connectivity issues, Skynats can help.

Need Professional Server Management Support?

Managing production servers involves more than configuring SSH keys. Businesses need ongoing server monitoring, security management, troubleshooting, and regular infrastructure maintenance to maintain reliable operations.

Skynats helps businesses manage and maintain their Linux and cloud infrastructure with professional server management services.

Whether you’re facing server access issues, managing multiple production environments, or looking for ongoing technical support, our team can help you manage your infrastructure requirements.

Let our experienced team take care of your server infrastructure while you focus on your business.

Picture of Sourav AJ

Sourav AJ

Sourav A J is a Level 3 System Engineer at Skynats Technologies, specializing in Linux server administration, cloud infrastructure, and advanced server management solutions.

Liked!! Share the post.

Get Support right now!

Start server management with our 24x7 monitoring and active support team

Subscribe and get your first issue fixed for Free!

Looking for server support and 24x7 monitoring?

Have doubts? Connect with us now.