New user can't mkdir ~/go/src in Ubuntu 18.04

Per I created a new user with sudo privileges who can successully ssh in:

root@dev: adduser tom
root@dev: # Give him sudo privileges
root@dev: usermod -aG sudo tom
root@dev: # Copy keys to this account
root@dev:$ rsync --archive --chown=tom:tom ~/.ssh /home/tom

Then I exit to my local OS, and ssh back in as the new user, tom.

The only other thing I did was install Golang:

tom@dev: cd ~
tom@dev: curl -O
tom@dev: sudo tar -xvf go1.12.1.linux-amd64.tar.gz -C /usr/local
tom@dev: sudo chown -R root:root /usr/local/go
tom@dev: # Must have used sudo on these but not sure???
tom@dev: mkdir -p $HOME/go/{bin,src}
tom@dev: nano ~/.profile
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin:/usr/local/go/bin
tom@dev: # Reload profile
tom@dev: . ~/.profile

When I go to create a new directory for a project in Go I get Permission denied:

tom@dev: mkdir ~/go/src/foo
mkdir: cannot create directory ‘foo’: Permission denied

I can do it with sudo but that’s tiring and doesn’t work right anyhow–if I try to nano main.go in the new directory I can’t save because I don’t have privileges.

What did I do wrong that my new user has sudo privileges but can’t even create file or directory without it?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer


I created a new droplet and replayed all of your commands without any errors to make sure you can create directories as normal user do this command

sudo chown -R tom:tom $HOME

To make sure tom is the owner of your home directory and all of its sub directories

Hope this helps

THAT DID IT!!! Thank you, @Mohsen47! Obviously the problem line was where I gave root, which I didn’t really understand was a user and not a privilege level, permissions–not tom.

What a huge relief!

Wait, but now I have another question. What is the difference between these two commands? Is that giving the user tom sudo privileges has NOTHING to do with the $HOME directory? I would assume that sudo privileges would just naturally be granted to that directory, but I’m beginning to suspect that’s nothing close to the truth.

# Give tom sudo privileges...
$ usermod -aG sudo tom

# ...but tom still can't even write to his
# own directory without this. WTF?
$ sudo chown -R tom:tom $HOME