Search code examples
sftpphpseclibssh-agent

phpseclib - SSH_AUTH_SOCK not found


I work with another company that is moving from regular FTP to SFTP for their connections. They have informed me that my existing username and password are the same, but that I now need to connect via SFTP on port 22. I have a couple of PHP scripts that do some basic things, like connect to their site, get a directory listing, and upload and download a file each day. Those all work fine on FTP, so I need to just swap out the protocol to SFTP.

After doing some research, the consensus seems to be that phpseclib is the easiest and most robust way to perform SFTP using PHP. My server is running Linux and Apache. I downloaded the library and tried to run just the basic example given by phpseclib, but I get an error:

Notice: SSH_AUTH_SOCK not found in System/SSH/Agent.php on line 244

When I look at Agent.php, I see that the script is looking for SSH_AUTH_SOCK to be defined in either $_SERVER or $_ENV. I must be missing something obvious, but I have no idea how to get past this error.


Solution

  • You are trying to connect to SSH authentication agent (ssh-agent).

    When the agent is run, it exports the SSH_AUTH_SOCK environment variable.

    What is obviously not happening in your case.

    But you didn't tell us, why are you trying to use the agent, if at all. And what did you do to set it up, if anything. So it's difficult to give you a more concrete advice.

    See also How is SSH_AUTH_SOCK setup and used by ssh-agent?