title: PHPSECLIB and SSH2
body: <p>I have been looking for a solution on how I could use <code>php</code> to establish a connection to a remote server and execute commands. Researching has brought two solutions to my attention; <code>phpseclib</code> and <code>ssh2</code>. I will try and keep my questions from turning this into a comparison post. From what I can tell they are both widely used solutions. <code>ssh2</code> is a php extension while <code>phpseclib</code> is a pure php library. It seems that you can also use <code>phpseclib</code> in conjunction with <code>ssh2</code>. I would much prefer to avoid needing to install an extension so I am more inclined to use <code>phpseclib</code>. However I do have some concerns.</p>
  <p><code>ssh2</code> has direct documentation with <code>php</code> does this mean it is a better solution to use?</p>
  <p>Most of the posts I see regarding <code>phpseclib</code> are several years old, is this still a &quot;modern-ish&quot; solution?</p>
  <p><code>phpseclib</code> (<a href="http://phpseclib.sourceforge.net/index.html" rel="nofollow noreferrer">found here</a>) says it was built for compatability with <code>php 4</code> with <code>2.0</code> being geared towards <code>php 5</code>. Is this an acceptable solution to those working with <code>php 7</code>?</p>
  <p>Here is an example using an <code>RSA key</code> to establish a <code>ssh</code> connection with <code>phpseclib 2.0</code></p>
  <pre><code>require __DIR__ . '/vendor/autoload.php';
  
  use phpseclib\Net\SSH2;
  use phpseclib\Crypt\RSA;
  
  $ssh = new SSH2('www.domain.tld');
  $key = new RSA();
  $key-&gt;loadKey(file_get_contents('privatekey'));
  if (!$ssh-&gt;login('username', $key)) {
      exit('Login Failed');
  }
  
  echo $ssh-&gt;exec('pwd');
  </code></pre>
  <p>I am still fairly new to <code>ssh</code> but if I understand the above correctly, so long as the remote server has a <code>.pub</code> key I can simply supply my connection with my local private key (and user) and I should be able to connect? Does the public key need to be somewhere specific?</p>