note 126939 added to function.ssh2-auth-pubkey-file

From: Date: Fri, 18 Mar 2022 15:46:11 +0000
Subject: note 126939 added to function.ssh2-auth-pubkey-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-217741@lists.php.net to get a copy of this message
The vendor we deal with requires the use of both password authentication AND a public/private key authentication. After much pain and testing, this is what we did to make it work, bypassing the need to install phpseclib: <?php $server = "subdomain.example.com"; $username = "username"; $password = "password"; $path_to_public_key = "file.pub"; $path_to_private_key = "file.priv"; // critical: permissions must be 0600!! $path_to_needed_file = "/path/to/file/needed.txt"; $ssh2 = ssh2_connect($server); @ssh2_auth_pubkey_file($ssh2,$username,$path_to_public_key,$path_to_private_key); // this returns a warning but it is normal and can be ignored ssh2_auth_password($ssh2,$username,$password); $sftp = ssh2_sftp($ssh2); $file = fopen("ssh2.sftp://" . intval($sftp). $path_to_needed_file,"r"); $content = fread($file,1024); fclose($file); ssh2_disconnect($ssh2); echo $content; ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 184.146.151.115) ---- Manual Page -- https://php.net/manual/en/function.ssh2-auth-pubkey-file.php Edit -- https://main.php.net/note/edit/126939 Del: integrated -- https://main.php.net/note/delete/126939/integrated Del: useless -- https://main.php.net/note/delete/126939/useless Del: bad code -- https://main.php.net/note/delete/126939/bad+code Del: spam -- https://main.php.net/note/delete/126939/spam Del: non-english -- https://main.php.net/note/delete/126939/non-english Del: in docs -- https://main.php.net/note/delete/126939/in+docs Del: other reasons-- https://main.php.net/note/delete/126939 Reject -- https://main.php.net/note/reject/126939 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217741) next »