Login as non-root user in terminal
This is a question that I would expect to quickly get an answer from google. However somehow google is failing me. Let's assume I'm logged in to a terminal session and I would like temporarily work as another non-root user whose password I know without leaving my session. When logged as this user I want the home directory, etc, for this user set up correctly until I log out. How do I do that?
I tried
su -- username
and then keying in the password, it did not produce any error but I saw no visible changes of the command prompt it would still say myname@myhost. The home directory also was that of myname and not the new login I tried to login as.
I'm - as it's apparent now - quite inexperienced in linux/Ubuntu, so any info is welcome.
To which user you want to change to?
The problem is that you are trying to "su" into a user that does not have a shell assigned to it. Most of the users such as mysql, pulse, etc, created by the system or by some packages when you install software does not have a shell assigned.
You can check if a user has a shell assigned by looking into the /etc/passwd
file, just look at the end of the line of each user, if it says /bin/false
it means that it does not have a shell assigned, if it has something like /bin/bash
or any other shell, then you should be able to "su" into that user.
When i say "shell assigned" it basically means that it has "shell access"
still if the user does not have shell access, you can always execute commands as that user with
sudo -u user command
if you have sudo access then I would recommend
sudo su username -
It does basically the same thing, but only requires you to know your password not the other users.
however if you have the other users password:
su username -
should work just fine.
notice the 1 - and that it's at the end.