douyun1546 2018-05-25 12:39
浏览 100

无法使用Laravel 5.5中的SSH密钥连接到远程服务器?

I am trying to connect with remote server using SSH Key. I am generating SSH keypair using phpseclib 2.0 and I storing keys in the database. Here is how I am trying to connect.

Config::set('remote.connections.production.host',$server->ip);
Config::set('remote.connections.production.username',$server->username);
Config::set('remote.connections.production.keytext',$server->meta()->where('meta_key','private_key')->first()->meta_value);

I have public key corresponding to the private key I am using in remote server's ~/.ssh/authorized_keys file. The permissions for .ssh directory is 700 and permissions for authorized_keys is 600 which is perfect.

First I thought this might be a issue but then I tried to remove all from the private key before connecting but I am still getting unable to connect to remote server. I don't know where the issue is. I am trying since last two days without luck.

I think SSH key gets damaged once it enters into the database. Here is how I am generating and storing SSH keypair in the database.

$rsa = new RSA();
$rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
$keys = $rsa->createKey(2048);
$privateKey = $keys['privatekey'];
$publicKey = $keys['publickey'];

$server->meta()->create([
     'meta_key' => 'private_key',
     'meta_value' => $privateKey
]);

$server->meta()->create([
    'meta_key' => 'public_key',
    'meta_value' => $publicKey
]);

Any help would be appreciated. Keys are being generated for sure because I can see it in the database.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答