1

I created a new user golden in linux by running adduser command.

After that I am trying to generate ssh keys for that new user and every time I am getting permission denied error:

golden@machineA:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/golden/.ssh/id_rsa):
Could not create directory '/home/golden/.ssh': Permission denied

Any thoughts what is wrong?

Update:

golden@machineA:~$ pwd
/home/golden
golden@machineA:~$ ls -l
total 0
golden@machineA:~$ ls -lrth
total 0
golden@machineA:~$ ls -lrtha
total 20K
-rw-r--r-- 1 10001 10001  675 May 10 11:54 .profile
-rw-r--r-- 1 10001 10001 3.5K May 10 11:54 .bashrc
drwxr-xr-x 2 10001 10001 4.0K May 10 11:54 .
-rw-r--r-- 1 10001 10001  220 May 10 11:54 .bash_logout
drwxr-xr-x 8 root  root  4.0K May 10 15:44 ..

Update2:

golden@machineA:~$ ls -ld /home/golden
drwxr-xr-x 2 10001 10001 4096 May 10 11:54 /home/golden
golden@machineA:~$ id golden
uid=1001(golden) gid=1002(golden) groups=1002(golden)
  • Could you give us the ls -l outputs on the home directory? – phk May 10 '17 at 23:13
  • updated the question – user5447339 May 10 '17 at 23:19
  • add the -d flag as well and point directly at the home directory. ls -ld /home/golden. Also output of id golden – ivanivan May 10 '17 at 23:24
  • updated the question again with details. – user5447339 May 10 '17 at 23:29
4

The owner of /home/golden is user 10001, not user golden. Normally, when you create an account, this creates a home directory for the user, and that home directory would of course belong to the user.

The reason this didn't happen here is probably that /home/golden already existed. Depending on the options you passed to adduser, it may or may not have told you about this. The reason /home/golden existed is presumably because there used to be an account called golden with the user id 10001, then this account was removed without deleting the home directory. Now there is a user account called golden again, but with a different user ID.

Assuming that this is what happened, and user 10001 no longer exists, you can change the ownership of /home/golden to the new account. Of course this allows the new user to see the files that the old user left behind, but in your case there are no interesting files anyway.

sudo chown -R golden:golden /home/golden

If you delete an account, you should either remove its home directory (deluser --remove-home) or rename it (mv /home/golden /home/golden.1001.archived).

  • let me try again by deleting user and its home directory. – user5447339 May 10 '17 at 23:48
  • Most distros also have "user dirs setup" packages that can auto generate a new user`s Home dirs plus Documents, Pictures, etc. – nannerpuss May 11 '17 at 1:14
  • @nannerpuss Creating Freedesktop directories like Documents and so on is irrelevant here. That doesn't do anything about the home directory itself. The Freedesktop directories would be created by applications if they want to store things in them anyway. – Gilles 'SO- stop being evil' May 11 '17 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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