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

<p>Another tip which is unrelated to your problem, the <code>user</code> resource has a property <code>manage_home</code> (<a href="https://docs.chef.io/resource_user.html#properties" rel="nofollow noreferrer">https://docs.chef.io/resource_user.html#properties</a>) which will create the home directory for you and will you save a redundant resource.</p>

CC BY-SA 3.0
2018-01-13T13:38:24.957Z
you were correct! and thanks for the tip! - so that's what I was missing
alexakarpov
CC BY-SA 3.0
2018-01-26T13:04:58.763Z
@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
CC BY-SA 3.0
2018-01-13T11:33:12.073Z
2018-01-26T09:28:21.750Z
2018-01-26T09:28:21.750Z
eyalzek
<p>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.</p>

<p>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.</p>

<pre><code>user 'foox' do
  comment 'test me'
  uid '6711'
  home '/home/foox'
  shell '/bin/bash'
  password '&lt;password_shadow_here&gt;'
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
</code></pre>

<p>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 -- <code>Permission denied (publickey)</code> -- 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.</p>

<p>I guess there's something missing in my recipe, then?</p>

<chef><linux>
What's missing from this simple recipe that creates a user?
alexakarpov
# What's missing from this simple recipe that creates a user?

(Asked by: username_0 on 2018-01-12)

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?

**Tags:** chef, linux


---

## 1 answers

### Answer by username_1 on 2018-01-13. Score: 7 | Accepted answer

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.

> **Comments:**
> **username_0**: you were correct! and thanks for the tip! - so that's what I was missing  
> **username_2**: @username_0 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.  

---

