[RESOLVED] Not allowed to run/sudo commands as ghost user

Default pristine install breaks reproducible on the following error:

Debug Information:
    OS: Ubuntu, v16.04
    Node Version: v8.9.0
    Ghost-CLI Version: 1.6.0
    Environment: production
    Command: 'ghost install'
Message: The database migration in Ghost encountered an error.
Help: https://docs.ghost.org/v1/docs/troubleshooting#section-general-update-error
--------------- stderr ---------------
Sorry, user vagrant is not allowed to execute '/home/vagrant/projects/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /home/vagrant/projects/ghost/current' as ghost on cakebox.

Probably not related but user vagrant logs in using certificate based authentication

Running the following command manually produces the same error:

sudo -u ghost /home/vagrant/projects/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /home/vagrant/projects/ghost/current

Any pointers to what should be the expected behavior here more than welcome.

Hi there!

Congrats on being the first person to post a support question here :slight_smile:

I’m not 100% sure, but I think the issue you are running into is due to trying to install Ghost in a user folder, e.g. /home/vagrant.

This section of the docs: https://docs.ghost.org/v1/docs/install#section-create-a-new-folder highlights this as a gotcha.

I’d suggest installing in /var/www/<your-folder-name> as recommended in the docs.

Come back and let us know if that works. If not, we can look into it further.

2 Likes

Haha, did not want to alienate anyone by creating a GH ticket :wink:

Anyway, exact same result using:

sudo mkdir -p /var/www/ghost
sudo chown vagrant:vagrant /var/www/ghost/ -R
sudo chmod 775 /var/www/ghost/ -R
cd /var/www/ghost
ghost install

I think the cause is in the error message: user vagrant cannot run the command as user ghost.

  • is this the intended behavior?
  • any pointer to where this command is being generated?

How did you setup the vagrant user? It seems like that user might not have sudo permissions.

This is also mentioned in the docs: https://docs.ghost.org/docs/install#section-super-user-privileges.

However, it sounds like you might be trying to set this up using some external tools for management, and might not want to grant the vagrant user verbatim sudo access.

If that’s the case, it is also possible to grant the vagrant user the ability to execute commands as the ghost user: su - Problem executing command as a different user with sudo -u - Unix & Linux Stack Exchange

Our production install guide is extremely detailed: https://docs.ghost.org/docs/install. There’s a lot of content, but the reason for that is ensuring that we cover all of these cases.

You can also try running ghost doctor as that should be able to highlight problems, although it’s still a work in progress.

1 Like

Thanks for the pointers, spot on.

User vagrant did have sudo permissions but not for user ghost so without alterations this command failed:

sudo -u ghost /usr/bin/whoami (error identical to the installer error)

After adding this config to /etc/sudoers.d/vagrant the above command does work:

# Grant user `vagrant` permission to run specified commands as
# user `ghost`. Required to get throught the ghost-cli installer.

vagrant   ALL=(ALL) ALL

Confirmed fix. The installer now completes successfully.

The directory is of no relevance btw. Ghost installs just fine in any directory I wish.

Thanks for your time, much obliged :blush:

I can’t seem to find a “close” button. Does this forum require/support it?

The install might work fine in any directory, but there’s also updates to consider. The directory is of consequence, using the correct location ensures that all ghost commands continue to work for the lifetime of the site :slight_smile: