How To SSH As Nginx-User?

The directory /var/www/vhosts which WordPress is installed is owned by the user of Nginx who runs the web server, so you can’t upload files there with sftp client and so on.
So, here is how to ssh as the Nginx user.

A login shell is not set up for the Nginx user, so first of all you need to set it up.
Using the command below, you can set it up as bash.

$ sudo /usr/sbin/usermod -s /bin/bash nginx

Then change the Nginx user’s password to use the passwd command.

$ sudo passwd nginx

Next, change the home directory of the Nginx user to /var/www/vhosts.
While many processes are running as Nginx, you can’t change the home directory, so stop Nginx and php-fpm process then change the home directory using usermod.
After changing the home directory, start Nginx and php-fpm to execute the command below.

$ sudo /sbin/service monit stop
$ sudo /sbin/service nginx stop
$ sudo /sbin/service php-fpm stop
$ sudo /usr/sbin/usermod -d /var/www/vhosts nginx
$ sudo /sbin/service php-fpm start
$ sudo /sbin/service nginx start
$ sudo /sbin/service monit start
  • Please note that if you are using AMIMOTO HHVM, you need to stop hhvm instad of php-fpm, such as:
$ Sudo / sbin / service php-fpm stop
$ Sudo / sbin / service php-fpm start

replace with:

$ Sudo / sbin / service hhvm stop
$ Sudo / sbin / service hhvm start

After that, enable to use the same pem key of ec2-user, copy .ssh/authorized_keys.

$ sudo mkdir /var/www/vhosts/.ssh
$ sudo cp /home/ec2-user/.ssh/authorized_keys /var/www/vhosts/.ssh/
$ sudo chown -R nginx:nginx /var/www/vhosts/.ssh/

That’s it. Now you can ssh with the Nginx user.

 
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk