4

How can I direct processes started on remote machines via ssh to run with a certain umask? I want this to apply to commands run as part of standard Capistrano recipes too, so I can't just make an explicit call to "umask" part of the command.

It does not appear that ~/.bash_profile on the remote machine is read, with the way that Capistrano invokes remote commands.

gcbenison
  • 11,723
  • 4
  • 44
  • 82

4 Answers4

3

I was confronted to the same issue and got around it by using the then-undocumented SSHKit.config.umask in config/deploy.rb. Note that this will set the umask for every ssh command.

beauby
  • 550
  • 3
  • 11
  • 1
    Just a note to say this doesn't work if you use the `execute('some command')` syntax, you have to use `execute(:some, 'command')` so that it is in interpreted via the [command map](https://github.com/capistrano/sshkit#the-command-map) – robd Apr 09 '15 at 16:02
  • This works only for Capistrano 3. Capistrano 2 doesn't use SSHKit. – Julian Mehnle Mar 03 '16 at 19:46
2

Put umask 0002 in the .bashrc of the user account you use to deploy.

Alain Beauvois
  • 5,896
  • 3
  • 44
  • 26
  • This works. i had my umash in my deploy user's .bash_profile file but realized for a passwordless ssh user this profile file seems to be not used and .bashrc does – armyofda12mnkeys Mar 26 '18 at 15:52
0

Agreed with Alain--set the umask in your .bashrc instead of .bash_profile. When deploying with Capistrano in a typical setup, your .bash_profile isn't loaded by default. Reading up on the difference between .bashrc and .bash_profile will help in understanding the purposes of the two. I have environment variables set in my .bashrc file and they are certainly used when I deploy or for running any other commands with capistrano.

Another option is to create a task to set your umask value before you begin creating files on deploy. For example, in Cap 3, you can use this:

task :set_umask do
  on roles(:all) do |host|
    execute "umask 0002"
  end
end
before "deploy:starting", "set_umask"
Community
  • 1
  • 1
alkalinecoffee
  • 1,003
  • 8
  • 20
0

@beauby's answer using SSHKit is good, but it works only for Capistrano 3 as Capistrano 2 doesn't use SSHKit.

A common problem in relation to umask and Capistrano is that bundle install installs gems with permissions that are too restrictive. For this specific issue, the solution I've found for Capistrano 2 is to say:

namespace :bundle do
  task :postinstall do
    run "chmod -R u=rwX,go=rX #{bundle_dir}"
  end
end

after 'bundle:install', 'bundle:postinstall'
Julian Mehnle
  • 156
  • 11