Score:0

How to repair user directory on Ubuntu server 20.04

us flag

For a project I have two servers, staging and production. The project is very old and I had not upgraded the OS from Ubuntu 14.04. As upgrading was out of question, recently I migrated the production server to a new VPS with Ubuntu 20.04.2. I am not sure where I went wrong, but these are now the symptoms:

Worong Promot
Whenever I SSH into the server as root all is normal, but when I switch to the normal user with su appuser the prompt becomes a bare $, no username, no host name and no path in the prompt.

No auto-completion
Also, I am unable to autocomplete paths in commands. I.e. when I type /ho and hit TAB, instead of the line becoming /home a literal tab character is added like /ho .

No command history
When I hit the UP key, instead of getting the last executed command, the line becomes $ ^[[A.

Cron jobs not executed
I have several cronjobs and I am sure there is no issue with the defining line or the service they call as they worked in the old production server and still work in the staging server. The jobs are not executed at all on the new server.

Missing files
I compared the list of files on the staging server and the new production server and noticed a number of files are missing in the new server. For example, there was no .bashrc file in the new servers's /home/appuser directory. I added the file manually but nothing changed. So I thought I should seek help.

How can I repair the appuser?

Mikael H avatar
br flag
Looks like user creation went wrong. Usually the contents of `/etc/skel` would be copied to new user accounts. Try doing that manually, fix the file permissions if applicable, and then re-login the `appuser` account.
Gabriel Núñez Yuvé avatar
cn flag
Just to be sure, did you check that the home folder and the default shell are set for that user in `/etc/passwd` ?
Majid Fouladpour avatar
us flag
@GabrielNúñezYuvé Good catch! In /etc/passwd I have this line for appuser: `appuser:x:1000:1000::/home/appuser:/bin/sh` which interestingly is different from that of root which is: `root:x:0:0:root:/root:/bin/bash` so I have an empty token after group ID and `sh` in place of `bash`. I had compared the home directory with `/etc/skel` as recommended by Mikael but found no missing files. Please add an answer and advise if it is wise to edit the `/etc/passwd` with nano, or if it should be done with a different tool. Thanks!
Score:0
cn flag

The default shell looks like it's a "minimal" shell. If you wish the appuser to have the same shell as root you should change the default shell to /bin/bash.
You can do this by editing the /etc/passwd file and replace the /bin/sh with /bin/bash using your preferred text editor (such as vi, vim or nano), or the other option is using the chsh command, like:

chsh appuser -s /bin/bash

Hope it helps!

Majid Fouladpour avatar
us flag
I used `vipw` instead of using nano directly and after adding a name token and changing `/bin/sh` to `/bin/bash`, as you had hinted, all symptoms were fixed. Thank you! Using `vipw` was something I learned about in this article titled *The Right Way To Edit /etc/passwd And /etc/group Files In Linux* - link: https://web.archive.org/web/20210331085207/https://ostechnix.com/the-right-way-to-edit-etc-passwd-and-etc-group-files-in-linux/
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.