0

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Bill Smith
  • 30
  • 1
  • 4

2 Answers2

2

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?

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I am only trying to use ssh-agent because I believe it is required to conduct the sftp session. sftp runs on top of an ssh process if I understand it correctly. I've made a little progress with the help of your link, and this page; http://blog.joncairns.com/2013/12/understanding-ssh-agent-and-ssh-add/ . I've now created a shell script which runs 'eval $(ssh-agent)' to launch the process and add the missing environment variable to the session, then it runs my php script, and finally a ps command to kill the ssh-agent process when the php script is done. – Bill Smith Mar 28 '15 at 13:09
  • No, ssh-agent is not required for SSH, nor SFTP. It's a way to ease frequent **interactive** authentications. It's generally not designated for automation. – Martin Prikryl Mar 28 '15 at 13:16
  • @Bill Smith - The ssh-agent process isn't something you should be starting and stopping every time you make a page load. That's like starting up mysql-server and stopping it after every page load. It's designed to run continuously in the background. – neubert Mar 28 '15 at 14:11
  • I understand now. My mistake was using the examples that came with the install, which were focused on using ssh, not sftp. I found the sftp relevant examples here: http://phpseclib.sourceforge.net/sftp/intro.html and I have it working now, and am not using ssh-agent at all. Thanks for all your help. – Bill Smith Mar 29 '15 at 13:55
1

Run the bellow command:

eval ssh-agent -s

It works fine for me.

Vega
  • 27,856
  • 27
  • 95
  • 103
jigetage
  • 11
  • 1