1

I mistakenly put a sh script in /etc/profile.d to automatically run some commands after login. the first of the script is running

#!/bin/bash
sudo su - userb
several normal commands

However when I login as "usera", then running the script, it required to enter userb password for the next command running. The problem is I don't have userb password, I have tried ctrl-c and input incorrect password few times, they caused direct session end. ctrl-z is also not working

Is that possible to not run the script or get back to "usera" so that I can manually remove the script?

1
  • sudo asks for the password of usera, not the password of userb. Apr 20, 2020 at 8:45

1 Answer 1

0

Log in by specifying bash with the --noprofile parameter.

From the documentation:

--noprofile
Do not read either the system-wide startup file /etc/profile or any of the personal initialization files ~/.bash_profile, ~/.bash_login, or ~/.profile. By default, bash reads these files when it is invoked as a login shell (see INVOCATION below).

To use this:

ssh usera@yourserver bash --noprofile

Don't be alarmed if this doesn't seem to work, if the login succeeds you'll get nothing, not even a prompt (this is all set by login scripts). But you can use the server as usual.

2
  • Many thanks! I tried two ways below, but userb password is still needed, do you see the issue? 1. Putty-Connection-SSH-Remote command:ssh usera@serverIP bash --noprofile 2. Putty-Connection-SSH-Remote command:/bin/bash --noprofile
    – ulamurt
    Apr 20, 2020 at 9:13
  • I don't see any way to do this with PuTTY. Looks like you need a different ssh client. I used this with the openssh client from the Windows Linux Subsystem. Apr 20, 2020 at 9:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .