Change user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change user
# 1  
Old 08-06-2019
Change user

Hi All,

need your assistance, how can i change user again after i change my user.

here is the code that i tried

Code:
su - myuser #success
su - webuser ##what i want to try is to change user again to webuser from myuser account

my output is it cannot change to webuser account. only in myuser.

Pls advise,
TIA
# 2  
Old 08-06-2019
Off hand, my first guess is that your webuser account does not have a valid shell specified in the password file.
# 3  
Old 08-06-2019
yes sir. what i only did in my script is su again after su in myuser.
# 4  
Old 08-06-2019
su should not allow a regular user to start a shell or process for another user without a password. Only root user can do that.
# 5  
Old 08-06-2019
Hi,

As Neo has said, the most likely explanation here is that myuser has a valid shell set in /etc/passwd, whereas webuser does not.

Witness the following example:

Code:
# finger -l unixforum
Login: unixforum                        Name: 
Directory: /home/unixforum              Shell: /bin/bash
Never logged in.
No mail.
No Plan.
# finger -l test
Login: test                             Name: 
Directory: /home/test                   Shell: /bin/false
Never logged in.
No mail.
No Plan.
#

Here we start off as root. We see that the account unixforum has a shell of /bin/bash, whereas the account test has a shell of /bin/false - in other words, it will never be able to have any kind of interactive logon session.

Let's see what happens now if we try to switch through these, starting off again as root:

Code:
# whoami
root
# su - unixforum
$ whoami   
unixforum
$ su - test
Password: 
No directory, logging in with HOME=/
$ whoami
unixforum
$

We were able to switch user from root to unixforum without a password (something only root can do with su, as per rdrtx1's advice). However, when we tried to switch from unixforum to test it didn't work, since we can't get a shell prompt for a user that doesn't have a valid shell set.

Hope that this helps you to see a bit clearer how this works. If I've gotten the wrong end of the stick here and if what I'm describing doesn't match your problem, then if you can provide output for what's failing or otherwise give a more detailed description of what exactly isn't working we can take things from there.
These 2 Users Gave Thanks to drysdalk For This Post:
# 6  
Old 08-06-2019
hmm.. i tried to manual
Code:
sudo su - webuser - c "test. sh"

from myuser account and it says sorry user is not allowed to execute '/bin/su - webuser - c test. sh' does it mean i dont have rights to execute command while in sudo su? but if tried to change user only webuser then execute shell script manually it works. is there any other way to execute script in webuser while im in myuser?

TIA
# 7  
Old 08-06-2019
Hello,

Yes, that's correct - this error means that the user myuser is not allowed to run the su command via sudo. That's not unusual, and in fact is generally good practice. If you let regular users run the su command via sudo (and especially if you let them run commands via sudo without being prompted for a password) then this can be a fairly big security hole, as it would allow users to (for example) switch to the root user without needing to know any passwords at all other than their own.

So, you could edit the sudoers file to allow myuser to run su via sudo, but you need to be sure you're definitely happy security-wise doing that. You can do that by typing visudo as root, which will open up the sudoers file in your default editor and allow you to make whatever changes you want.
This User Gave Thanks to drysdalk For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

How to change normal user id to LDAP user id?

If I create a new user id test: mkuser id=400 test then I want it to LDAP user: chuser -R LDAP SYSTEM=LDAP registry=LDAP test It shows: 3004-687 User "test" does not exist. How to do? (4 Replies)
Discussion started by: rainbow_bean
4 Replies

2. Red Hat

Change user from SH TO CSH

Dear Experts, I'm currently working on a Red Hat Linux env. I have been working in AIX. My user is set to use SH default so when it logs in, we have to manually csh to do few things. I know you can change this in AIX using smitty tool. is there any similar too in LINUX that can change it? ... (7 Replies)
Discussion started by: Afi_Linux
7 Replies

3. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

4. Shell Programming and Scripting

Change user

Hi, I have to change many times user in a script. With the command su userName I receive the request for password. I need to open a session with another user I would put the password at the beginning. How can I do it? Thanks, bye bye. ---------- Post updated 22-04-10 at 10:58 AM ----------... (9 Replies)
Discussion started by: abdujaparov
9 Replies

5. UNIX for Dummies Questions & Answers

change user> to user@host> ssh prompt

Hi, I was wondering how to change the prompt for my ssh login. At the moment it is like user> while I'd like it to be as user@host> It is in the .bash_profile or .ssh ??? Thanks (2 Replies)
Discussion started by: pmasterkim
2 Replies

6. Shell Programming and Scripting

How do i change to super user then revert back to ordinary user ,using shell script?

Hi all, I am trying to eject the cdrom from a livecd after certain stage... Now assuming that it is possible to eject,please consider my issue!!! The OS boots into a regular user by default...so i am unable to use the eject command to push out the drive... However if i try pfexec eject it... (3 Replies)
Discussion started by: wrapster
3 Replies

7. Forum Support Area for Unregistered Users & Account Problems

Change of user name

I am on several other Forums under the handle of FloridaBD and therefore would like to request that my user name here on Unix forums be changed from SunBurntYux to FloridaBSD Thanks. (1 Reply)
Discussion started by: SunBurntYux
1 Replies

8. Post Here to Contact Site Administrators and Moderators

User name change?

Hello, I love the service. My username is Jmt. Can I change that to WebKruncher? Thanks, -Jmt WebKruncher.com - sole proprietor. (1 Reply)
Discussion started by: Jmt
1 Replies
Login or Register to Ask a Question