As others said here, it's not possible to protect only a program like gnome-terminal or other terminal from key logging, only if you restrict standard users to execute any key logger or if you stop/pause any key logger process.
Next I will show you how you can do these in case of xinput command, but the same methods can be used for any other key logger. If a key logger uses xinput command, it is not necessary to apply the method upon it as long as you apply it upon xinput.
1. Restrict standard users to use xinput command
You can restrict standard users to use xinput command using the following command:
sudo chmod go-x /usr/bin/xinput
2. Restrict standard users to use xinput command with test-xi2 argument
You can restrict standard users to use xinput command with test-xi2 argument by writing a wrapper for this command. To do this, go in terminal and follow the instructions below:
Get root privileges:
sudo -i
Move xinput file in another directory which is not in any user's PATH (for example /opt):
mv /usr/bin/xinput /new/path/to/xinput
Create your wrapper for xinput command in /usr/bin:
gedit /usr/bin/xinput
Add the following script inside:
#!/bin/bash
if [ "$@" != "${@/test-xi2/}" -a "$(whoami)" != "root" ]; then
echo "`basename $0` $@: Permission denied"
else
/new/path/to/xinput $@
fi
Save the file and close it.
Make the new wrapper executable:
chmod +x /usr/bin/xinput
While first method is safety, using second method, the user may still circumvent it by calling the original xinput directly if he know its new location.
3. Stop/pause any xinput process
You can stop or pause any xinput process before to enter a password or anything else that you don't want to be logged. To do this, add the following bash function at the end of your ~/.bashrc file:
processof () {
xinput_pids=" $(pidof $1) "
if [ "$xinput_pids" = " " ]; then
echo "Nothing to stop/pause/continue. $1: no such process!"
return
fi
for pid in $xinput_pids; do
case $2 in
"stop")
kill $pid
echo "$1: stopped"
;;
"pause")
kill -stop $pid
echo "$1: paused"
;;
"continue")
kill -cont $pid
echo "$1: continue"
;;
*)
echo "$1 is runnig"
;;
esac
done
}
Now, after you reopen your terminal, anytime you want, using this function you can:
stop/kill all xinput processes:
processof xinput stop
pause all xinput processes:
processof xinput pause
resume all xinput processes:
processof xinput continue
In fact, with this function you can stop/pause any process do you wish before to do something (such as entering the password):
processof [process_name] [stop|pause|continue]
If you don't know how to detect how to detect an active keylogger on your system, see:
These methods maybe are not the best solutions, but I hope to give you an idea about what you can do...