0

I have a user 'test' and I had modified /etc/passwd file to run a certain script of my own (lets call it somescript.sh) whenever 'test' logs-in or does ssh.

I later changed the '/etc/passwd' file to run '/bin/bash' (the default program to run) whenever 'test' login-in or does ssh, but still whenever 'test' logs-in/ssh the previous script (somescript.sh) runs and not bash.

Not sure who to rectify this. Please help. Thanks

EDIT

test:x:1001:1001:test,,,:/home/test:/home/admin/scripts/script.sh ==> before

script.sh is a shell script that accepts users inputs in a loop, there is a option 'quit' on which I break from the loop and the script ends

test:x:1001:1001:test,,,:/home/test:/bin/bash ==> after

  • Did you use usermod for changing the login shell? – Tero Kilkanen Jul 14 '15 at 0:11
  • No, I did not. Do I have to use usermod command? I thought if just by changing /etc/passwd file should do the trick as before. – CodeWithPride Jul 14 '15 at 0:13
  • There can be all kinds of caching mechanisms inside the system that aren't updated when you edit the file directly. The chsh command mentioned below is even better. – Tero Kilkanen Jul 14 '15 at 0:16
  • chsh and usermod both did not help. Still facing the same issue – CodeWithPride Jul 14 '15 at 0:39
  • Have you verified that the change was also reflected in /etc/passwd- and that the backup is not accidentally being used? – Matt Jul 14 '15 at 1:08
0

Depending on what somescript.sh does there may be better ways to execute it upon login than by using /etc/passwd. If possible you can login as test and use

chsh -s /bin/bash

that should set the login shell for test to bash. Once that has been done there is some great information in this answer about the different scripts that run when the bash shell starts, the order they run in, etc. Once you know the appropriate file you can add the line

source /path/to/somescript.sh

to that file and it will run every time the user logs in.

  • chsh did not help. Still facing the same problem. – CodeWithPride Jul 14 '15 at 0:39
  • is there any chance you can post an example of /etc/passwd with the changes that were made before and after? obviously not the exact /etc/passwd you are using, but if you could boot a live OS image or clean/disposable VM and try to recreate the issue in a clean environment more details and/or step by step snapshots of the relevant files would be useful. On a somewhat related note have you tried deleting and recreating the test user? – Matt Jul 14 '15 at 0:52
  • I have edited the question with before and after changes of /etc/passwd. I have not tried deleting and re-creating test user. – CodeWithPride Jul 14 '15 at 1:01
  • The link to another question really helped. Thanks – CodeWithPride Jul 14 '15 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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