0

Actually I am trying to create a password protection for my terminal. Means when we start the terminal it will ask for password first.

But the problem is that if I press CTRL + z then the password script will stop.

How to fix this.

mklement0
  • 382,024
  • 64
  • 607
  • 775
Anonymous
  • 21
  • 7
  • 1
    Hi ! As of now, you question needs more focus. Why did you tag your question `powershell` and `bash` ? one is for windows, the other is for linux. – Aserre Dec 28 '21 at 10:31
  • What you are looking for is `trap`. Here is a similar question on [unix stack exchange](https://unix.stackexchange.com/questions/227459/make-a-process-unkillable-on-linux) – Aserre Dec 28 '21 at 10:31
  • 1
    Also, a small tip : if you are storing your password in a text file somewhere, use a hashing program like `sha256sum` and compare the stored hash with the hashed input – Aserre Dec 28 '21 at 10:37
  • Technically speaking, the script does not **stop**, but is suspended. The fact that the shell outputs _stopped_, is a bit misleading. You can bring it back to front via `fg`. Of course the interesting question is, **why** you press control-z, if you don't want to suspend it. – user1934428 Dec 28 '21 at 10:46

1 Answers1

0

use trap command:

trap 'printf "you can't do this"' SIGTSTP 

Control+C sends SIGINT which will interrupt the application

Control+Z sends SIGTSTP