Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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
share|improve this answer
    
still if the user does not have shell access, you can always execute commands as that user with "sudo -u user command" –  Sam Nov 16 '12 at 5:55
    
Yes, that's it. Thank you. –  zespri Nov 16 '12 at 5:57
    
Append -s /bin/bash to your su command or use chsh -u username -s /bin/bash to change the shell for a user. Beware of the security implications this might have. –  gertvdijk Nov 16 '12 at 8:24

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.

share|improve this answer
    
Somehow both ways you described behave exactly as mine - the command is accepted without error but the home directory is not right and the prompt says that I'm still the original user. If I do logout after that I logout completely. –  zespri Nov 16 '12 at 5:43
    
Ok, is the user your logging in as allowed to log in? You can block account from logging in by setting their shell to "true" and that will do exactly as you describe. This used to be used alot on "system" account like "apache" and "ftp" To check sudo cat /etc/passwd DO NOT PASTE THE CONTENT HERE. Just eyeball it and make sure the user has a real shell as the last little bit of their line. –  coteyr Nov 16 '12 at 5:50
1  
side note, the more proper way to do this is setting a shell to "false" which will throw an error. Though some systems and accounts still use true for technical or psudo-security reasons (to aggravate the snot out of wana-be-hackers) –  coteyr Nov 16 '12 at 5:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.