简体   繁体   中英

Wordpress sftp automatic update - Could not find the wp-content directory

I am trying to configure the sftp automatic update on Wordpress. It does not work: I always got "wp-content can not be found".

The configuration I have is as follow:

  • each site has its owned user
  • the site is located under user home directory : /home/{user}/www
  • the user is chrooted to its home directory : /home/{user}

sftp is working ok for my user (using command line or software like filezilla).

In wordpress config, I got the below parameter:

define('FS_METHOD', 'ssh2');
define('FTP_HOST', '127.0.0.1:22');
define('FTP_USER', 'test');
define('FTP_PASSWD', '');
define('FTP_PUBKEY','/home/test/wp-rsa.pub');
define('FTP_PRIKEY','/home/test/wp-rsa');

This unfortunately does not work. During update, wordpress can not found the wp-content directory.

Issue is that the ABSPATH is equal to /home/{user}/www but through sftp it should only be /www (due to chrooted). I trie to use the FTP_BASE configuration variable but after looking the Wordpress code, it looks like that in case of sftp connection, it does not care about the value of FTP_BASE :(

I read many articles on the web about the sftp settings but none seems to use the chrooted mechanism.

So is there a way to make wordpress automatic update works with my settings?

Thx in advance!!

I was able to make it work by also chrooting the SFTP user.

  1. I have this at the very end of my /etc/ssh/sshd_config:

    Subsystem sftp internal-sftp
    Match Group sftp-only
    ChrootDirectory %h
    ForceCommand internal-sftp
    AllowTcpForwarding no

...don't forget to comment out any other instance of 'Subsystem sftp'.
Restart sshd.
Also note that this will allow only SFTP for any user that's a member of the 'sftp-only' group - no plain SSH shell. If you want to allow plain ssh sessions as well, try removing the 'ForceCommand' entry - haven't try it but should work.

  1. Add the user to the 'sftp-only' group, eg:

    addgroup sftp-only
    usermod -G sftp-only -a {user}

3.In /etc/passwd set the home of the user to be the same as the PHP's chroot folder, in your case they both will be /home/{user} I think and no change will be needed, but in my case I have the PHP chroot set as /home/{user}/php and I got to change that to match in /etc/password for the entry for {user}.
4. Make sure any component of the path to that home is owned by root so the SFTP chroot function allows the login - in this case both /home and /home/{user} must be owned by root.
5. Try to SFTP with FileZilla - make sure you now see only inside the user's home/chroot.

For me, after unifying what SFTP and PHP see as their path, the SFTP plugin now worked as expected. Of course the SFTP {user} must have write rights over the WP root.

GL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM