4

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 '<password_shadow_here>'
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?

1 Answer 1

7

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.

2
  • you were correct! and thanks for the tip! - so that's what I was missing Jan 13, 2018 at 13:38
  • @alexakarpov and a small point avoid using numeric modes in chef recipes, this has the potential to break in very surprising ways when you set directory modes as starting with a 0 you're defining an octal number and not what you're likely after.You should declare them as string like mode '0600' to avoid that.
    – Tensibai
    Jan 26, 2018 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.