stechstudio / laravel-ssh-tunnel

Easy creation & maintenance of an SSH Tunnel for Laravel/Lumen
MIT License
191 stars 49 forks source link

Syntax error: redirection unexpected #54

Closed dnsnx closed 3 years ago

dnsnx commented 3 years ago

We are facing an issue with the solution. We are running a Debian Linux.

The connection cannot be established. For example, when we run the php artisan migrate command, we get the following error:

$ php artisan migrate sh: 1: Syntax error: redirection unexpected

ErrorException

Could Not Create SSH Tunnel with command: /usr/bin/ssh -N -i /var/ssh_keys/user_id_rsa -L 13306:127.0.0.1:3306 -p 22 user@targetserver.com Check your configuration.

at vendor/stechstudio/laravel-ssh-tunnel/src/Jobs/CreateTunnel.php:72 68▕ // Wait a bit until next iteration 69▕ usleep(config('tunneler.wait')); 70▕ } 71▕ ➜ 72▕ throw new \ErrorException(sprintf("Could Not Create SSH Tunnel with command:\n\t%s\nCheck your configuration.", 73▕ $this->sshCommand)); 74▕ } 75▕ 76▕

  +20 vendor frames

21 [internal]:0 Illuminate\Foundation\Application::Illuminate\Foundation{closure}()

  +5 vendor frames

27 artisan:37 Illuminate\Foundation\Console\Kernel::handle()

But when running the command

/usr/bin/ssh -N -i /home/user/.ssh/user_id_rsa -L 13306:127.0.0.1:3306 -p 22 user@targetserver.com

manually, the connection can be established without any error.

I know the location of the rsa key file is differently, but it is the same key. We copied to a different location and set the permissions to the www-data user.

This is from the laravel.log file:

[2021-10-04 08:49:08] production.ERROR: Could Not Create SSH Tunnel with command: /usr/bin/ssh -N -i /var/ssh_keys/user_id_rsa -L 13306:127.0.0.1:3306 -p 22 user@targetserver.com Check your configuration. {"exception":"[object] (ErrorException(code: 0): Could Not Create SSH Tunnel with command: \t/usr/bin/ssh -N -i /var/ssh_keys/user_id_rsa -L 13306:127.0.0.1:3306 -p 22 user@targetserver.com Check your configuration. at /var/www/homepageadministration/homepage-administration/vendor/stechstudio/laravel-ssh-tunnel/src/Jobs/CreateTunnel.php:72) [stacktrace]

0 /var/www/homepageadministration/homepage-administration/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): STS\Tunneler\Jobs\CreateTunnel->handle()

...

dnsnx commented 3 years ago

Ok, we found out what was causing the error. We added the NOHUP_LOG option in .env and got more specific error messages. It turned out, that the www-data user needed to accept the connection once:

The authenticity of host 'targetserver.com (159.xxx.xxx.xxx)' can't be established. ECDSA key fingerprint is SHA256:pmqqqH66/07274hns4L8eYLRQbyjcSaP4lQzRihBxma. Are you sure you want to continue connecting (yes/no/[fingerprint])?

But in the end we saw it is not the best way to use the www-data user to establish the ssh connection and used a different user.