New user cannot create files in its home directory

8,296

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).

Share:
8,296

Related videos on Youtube

user5447339
Author by

user5447339

Updated on September 18, 2022

Comments

  • user5447339
    user5447339 over 1 year

    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)
    
    • phk
      phk almost 7 years
      Could you give us the ls -l outputs on the home directory?
    • user5447339
      user5447339 almost 7 years
      updated the question
    • ivanivan
      ivanivan almost 7 years
      add the -d flag as well and point directly at the home directory. ls -ld /home/golden. Also output of id golden
    • user5447339
      user5447339 almost 7 years
      updated the question again with details.
  • user5447339
    user5447339 almost 7 years
    let me try again by deleting user and its home directory.
  • nannerpuss
    nannerpuss almost 7 years
    Most distros also have "user dirs setup" packages that can auto generate a new user`s Home dirs plus Documents, Pictures, etc.