SSHKit extension, for sudo operation with password input.
Add this line to your application's Gemfile:
gem 'sshkit-sudo'
And then execute:
$ bundle
If you're using Capistrano, add the following to your Capfile:
require 'sshkit/sudo'
This gem adds sudo
and execute!
command to SSHKit backends.
To execute a command with sudo, call sudo
instead of execute
.
sudo :cp, '~/something', '/something'
# Or as follows:
execute! :sudo, :cp, '~/something', '/something'
# Executing a command with sudo in Capistrano task
namespace :nginx do
desc 'Reload nginx'
task :reload do
on roles(:web), in: :sequence do
sudo :service, :nginx, :reload
end
end
desc 'Restart nginx'
task :restart do
on roles(:web), in: :sequence do
execute! :sudo, :service, :nginx, :restart
end
end
end
namespace :prov do
desc 'Install nginx'
task :nginx do
on roles(:web), in: :sequence do
within '/etc/apt' do
unless test :grep, '-Fxq', '"deb http://nginx.org/packages/debian/ wheezy nginx"', 'sources.list'
execute! :echo, '"deb http://nginx.org/packages/debian/ wheezy nginx"', '|', 'sudo tee -a sources.list'
execute! :echo, '"deb-src http://nginx.org/packages/debian/ wheezy nginx"', '|', 'sudo tee -a sources.list'
execute! :wget, '-q0 - http://nginx.org/keys/nginx_signing.key', '|', 'sudo apt-key add -'
sudo :'apt-get', :update
end
end
sudo :'apt-get', '-y install nginx'
end
end
end
- Fork it ( https://github.com/[my-github-username]/sshkit-sudo/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request