Earlier today I found myself needing to configure Rocketeer to deploy to a server that required commands to be run with sudo
. I’m not sure that this is particularly well documented so I thought I’d share how I did this here.
There’s a couple of settings that need configuring, both in the remote.php configuration file. First up we need to enable use of sudo
for some commands by setting it to true
:-
'sudo' => true,
Secondly, we need to tell Rocketeer which commands we are allowing it to run under sudo
. For example, let’s say we want to allow Rocketeer to run mkdir
, mv
, git
and ln
as root:-
'sudoed' => [
'mkdir',
'mv',
'git',
'ln',
],
Rocketeer will only run the commands defined using sudo
. This might seem a bit of a pain having to list out the commands here, but this adds a bit of security as we’re limiting what Rocketeer will run as a root user.
As with all other configuration options in Rocketeer you can specify these for specific connections using the contextual options in config.php. For example, rather than set the above settings in remote.php we could just set these for a ‘production’ connection:-
'on' => [
// Connections configuration
'connections' => [
'production' => [
'remote' => [
'sudo' => true,
'sudoed' => [
'mkdir',
'mv',
'git',
'ln',
],
]
]
],
],