HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

What's missing from this simple recipe that creates a user?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
thissimplecreateswhatuserrecipethatmissingfrom

Problem

I've spun many boxes in the cloud before, but was growing tired of going through the same dance; and as I'm trying to get familiar with Chef, I figured, that's a good use case to do a little learning.

Ah, that feeling when you think you know how it'll work - but it doesn't. Since I'm new to Chef, I suspect I'm not doing something right in this recipe, which is like my 2nd ever. NOTE: I understand there probably are 'cookbooks' out there that do something like that, but at this point I'm trying to build some ver basic knowledge with the simplest approach.

user 'foox' do
  comment 'test me'
  uid '6711'
  home '/home/foox'
  shell '/bin/bash'
  password ''
end

directory "/home/foox" do
  owner "foox"
  group "foox"
  mode 00755
  action :create
end

directory "/home/foox/.ssh" do
  owner "foox"
  group "foox"
  mode 00600
  action :create
end

file '/home/foox/.ssh/authorized_keys' do
  owner "foox"
  group "foox"
  mode "00600"
  content IO.read('/root/.ssh/authorized_keys')
  action :create
end


Now, this does create the user with a password and home folder with .ssh, and copies the public key from root's own file. But this system ends up failing to let me log in -- Permission denied (publickey) -- when using the same private key as what I have as my root's. But, well, root user wasn't created by my recipe. And if I create my own user manually, it's working fine.

I guess there's something missing in my recipe, then?

Solution

I'll put in an answer although I'm not 100% sure. I think that you got the permissions wrong on ~/.ssh and it should be 0700 instead of 0600, otherwise the user cannot access it.

Another tip which is unrelated to your problem, the user resource has a property manage_home (https://docs.chef.io/resource_user.html#properties) which will create the home directory for you and will you save a redundant resource.

Context

StackExchange DevOps Q#3075, answer score: 7

Revisions (0)

No revisions yet.