Report this

What is the reason for this report?

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

Posted on April 27, 2019

Per https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04 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 https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz
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?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.