laravel / forge-cli

The Laravel Forge CLI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error after deploying

tomsgad opened this issue · comments

  • Forge CLI Version: 0.1.5
    • PHP Version: 8.0.2
    • Operating System: WINNT
    • Error Message: Unable to connect to remote server. Maybe run [ssh:configure] to configure an SSH Key?

Description:

When I deploy to the site, the deployment actually works and the site is deployed. Just a weird thing after that. I get an error, Unable to connect to the remote server. I have the connection working hence I can deploy.

Steps To Reproduce:

forge deploy site

forge-cli

Before performing any tasks using the Forge CLI, you should ensure that you have added an SSH key for the forge user to your servers so that you can securely connect to them: https://forge.laravel.com/docs/1.0/accounts/cli.html#ssh-key-authentication.

The issue is... I have already done that. I have just confirmed again the ssh key is there. I have do it a fresh again now, am still getting the same error now.

Can you try forge ssh:test?

On my system, forge ssh:test gets the same results:

Unable to connect to remote server. Maybe run [ssh:configure] to configure an SSH Key?

I noticed when I generate SSH keys via forge-cli, their format is different than those I've generated manually.

Public keys I've successfully used before, generated w/o Forge CLI:

ssh-rsa xxxxx== user@machinename

Public keys Forge CLI generates:

-----BEGIN PUBLIC KEY-----
xxxxx
-----END PUBLIC KEY-----

Private keys successfully used before, generated w/o Forge CLI:

-----BEGIN OPENSSH PRIVATE KEY-----
xxxxxxxxxx
-----END OPENSSH PRIVATE KEY-----

Private keys generated by Forge CLI:

-----BEGIN PRIVATE KEY-----
xxxxx
-----END PRIVATE KEY-----

With the old one having quite a few more lines than the new one. I don't know enough about SSH protocol and how these things work to say what the tangible difference is between these formats.

Dumping around in RemoteRepository.php:ensureSshIsConfigured while running ssh:test, the SSH command that results is:

ssh -o ConnectTimeout=5 -o ControlMaster=auto -o ControlPersist=100 -o ControlPath=C:\Users\ethan/.laravel-forge/sockets/%h-%p-%r -o LogLevel=QUIET -t forge@161.35.102.160 -t exit 0

Its result is an empty string, the output array is empty, and the exit code is 255.

Changing the LogLevel to VERBOSE and just running this command directly, the error message alternates between Permission denied (publickey) and:

getsockname failed: Bad file descriptor
channel_send_open: channel 0: unexpected internal error

But I'm assuming that is a result of the failed connection on the first attempt. So something about the keys being generated isn't working, because I do see that the private key has been saved on the server successfully.

Though also worth mentioning - it's unclear to me how the SSH client is told what public key to present for authentication. I can't find anything in the key generation logic that actually associates a key (created by Forge CLI or reused during configuration) with a server, and the SSH command that gets generated, which I pasted above, also doesn't reference a key.

Can you try forge ssh:test?

Yah, when I run ssh:test, it passes. I get "SSH Key Based Secure Authentication Is Configured". But after deploying, I still get the same error

Hm, that suggests the issues are unrelated I suppose.

Forgoing forge-cli altogether to connect, but still using the SSH keys it generated, I get permission denied anyway:

ssh -i C:\Users\ethan\.ssh\ethan_rsa.pub forge@161.35.102.160
Load key "C:\\Users\\ethan\\.ssh\\ethan_rsa.pub": invalid format
forge@161.35.102.160: Permission denied (publickey).

But if I add my default key to the same server and attempt to log in, that works, with simply:

ssh forge@161.35.102.160