Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Defines ssh service name based on distro
default[:ssh][:service_name] = case node["platform_family"]
when "debian","ubuntu" then "ssh"
else "sshd"
end
#
# Port on which openssh listens on
default[:ssh][:port] = "22"
#
Expand Down Expand Up @@ -56,4 +62,4 @@
# shouldn't really enable root login, but if you really must, DO NOT enable
# password authentication. With both options enabled, your server will become
# very vulnerable.
default[:ssh][:root_authorized_keys] = []
default[:ssh][:root_authorized_keys] = []
3 changes: 2 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
maintainer_email "gerhard@lazu.co.uk"
license "Apache 2.0"
description "Configures openssh, adds system users"
version "1.4.0"
version "1.4.1"
name "ssh-cookbook"
15 changes: 6 additions & 9 deletions providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
bash "Adding #{new_resource.name} to sshd_config" do
code %{
set -x
if [[ $(cat /etc/ssh/sshd_config) =~ "#{new_resource.match}" ]]; then
sed -i "s/#*#{new_resource.match}.*/#{new_resource.string}/g" /etc/ssh/sshd_config
else
echo -en "#{new_resource.string}\n" >> /etc/ssh/sshd_config
fi
sed -i '/#*#{new_resource.match}.*/ d' /etc/ssh/sshd_config
echo -en "#{new_resource.string}\n" >> /etc/ssh/sshd_config
}
not_if %{ egrep -c "^#{new_resource.string}$" /etc/ssh/sshd_config -q }
notifies :restart, resources(:service => "ssh"), :delayed
notifies :restart, resources(:service => node[:ssh][:service_name]), :delayed
end
end

Expand All @@ -20,7 +17,7 @@
echo -en "#{new_resource.string}\n" >> /etc/ssh/sshd_config
}
not_if %{ [[ ! $(cat /etc/ssh/sshd_config) =~ "#{new_resource.match}" ]] }
notifies :restart, resources(:service => "ssh"), :delayed
notifies :restart, resources(:service => node[:ssh][:service_name]), :delayed
end
end

Expand All @@ -31,6 +28,6 @@
sed -i '/#{new_resource.match}.*/ d' /etc/ssh/sshd_config
}
only_if %{ egrep -c "^#{new_resource.string}$" /etc/ssh/sshd_config -q }
notifies :restart, resources(:service => "ssh"), :delayed
notifies :restart, resources(:service => node[:ssh][:service_name]), :delayed
end
end
end
4 changes: 3 additions & 1 deletion recipes/chroot.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
service "ssh"
service node[:ssh][:service_name] do
provider Chef::Provider::Service::Upstart if 'ubuntu' == node['platform'] && Chef::VersionConstraint.new('>= 12.04').include?(node['platform_version'])
end

ssh_config "Subsystem sftp" do
string "Subsystem sftp internal-sftp"
Expand Down
6 changes: 4 additions & 2 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
service "ssh"
service node[:ssh][:service_name] do
provider Chef::Provider::Service::Upstart if 'ubuntu' == node['platform'] && Chef::VersionConstraint.new('>= 12.04').include?(node['platform_version'])
end

ssh_config "Port" do
string "Port #{node[:ssh][:port]}"
Expand Down Expand Up @@ -51,4 +53,4 @@
ssh_authorized_keys "root" do
home "/root"
ssh_keys node[:ssh][:root_authorized_keys]
end
end