Score:0

Installing postgresql. Last line says: 'could not change directory to "home/user": Permission denied'

ma flag

I am getting ready for a coding bootcamp and have followed certain instructions to install Linux (Ubuntu v22.04). The installation went fine but then I am told to enter the following command into the terminal:

sudo apt-get update && sudo apt-get upgrade && sudo apt-get install git && sudo apt-get install curl postgresql postgresql-contrib && touch ~/.bash_profile && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash && source ~/.nvm/nvm.sh && nvm install node && nvm use node && sudo -u postgres createuser --superuser $USER && sudo -u postgres createdb $USER && git config --global credential.helper store

As I understand, this is to install Git, NVM, Node and Postgresql, and it seems the first 3 installed correctly, however, the last lines are as follows:

Now using node v20.4.0 (npm v9.7.2)
could not change directory to "/home/user": Permission denied
could not change directory to "/home/user": Permission denied

I think this is in relation to postgresql, however I am at a total loss on if this is an issue or not. The guide I am following does not say anything about it and this is my first time using Linux of any kind so I am unfamiliar with the terminology.

Would appreciate any advice/explanation as necessary.

cc flag
To narrow down where the error occurs, you can break up the huge command at the && s, enter each part in order in a terminal, and see the result. Is /home/user really the output, or did you edit out the actual username, or was the actual username "user"?
uz flag
Jos
It is probably significant that it says `home/user` and not `/home/user`.
Nick avatar
ma flag
@ubfan1 Thanks for the reply. I followed your advice and have isolated the error message to the line as follows: sudo -u postgres createuser --superuser $USER && sudo -u postgres createdb $USER . Also, to answer your question, I edited out the actual username. It actually reads as /home/nick
cc flag
Check the original instructions for the createdb command. It seems odd to me that the owner is postgres instead of the user. i.e. usually user Nick owns database nick.
Nick avatar
ma flag
I see, so if I understood correctly, the initial command instructed user (-u) postgres to create the database nick, where it should actually be something like sudo -u nick createdb $USER ? I also assume $USER stands for nick in other words?
hr flag
One thing that may be worth noting is that since the commands are chained with `&&`, the fact that the postgres `createdb` command was executed at all indicates that the preceding `createuser` command didn't actually *fail*. BTW what are the permissions on `/home/nick` - in particular, is the `x` bit set for `o`thers?
cc flag
@Nick Right, $USER is your username, echo $USER to see it. The database with the same name as USER is a default when no explicit database is given, so the command psql will open the database nick.
Nick avatar
ma flag
I see, so is there anything to be concerned about regarding the 'Permission denied' or should I just leave it as it is? I can confirm you were right and the psql command does open the nick-# database. @steeldriver how would I check the permissions regarding 'x' ? I right clicked the /nick folder and it says 'Others Access' is set to 'none'.
hr flag
@Nick it sounds like you have your answer, but you can confirm in the terminal with command `ls -ld /home/nick`
hr flag
... I'm curious if you have configured `sudo` to set `$HOME` to that of the invoking user instead of the target user (as was the default behavior on Ubuntu several years ago)? In that case, the messages you see may be simply that it is trying to write a `.psql_history` file to `/home/nick` instead of to the postgres user's home dir. See this somewhat related [could not change directory to "/home/corey/scripts": Permission denied](https://unix.stackexchange.com/a/396433/65304).
Nick avatar
ma flag
@steeldriver That's a good guess. I'll have a look into it. Do you think it could be that when the sudo -u postgres createdb $USER was executed it tried to store the database data in /home/nick ? Having investigated a bit more I can see the following: nick=# SHOW data_directory; data_directory ----------------------------- /var/lib/postgresql/14/main
hr flag
@Nick no I don't think it would try to store the *data* in /home/nick - just user-specific stuff like command history and possibly personal configuration settings
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.