LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   Hide SSH Terminal Script From User (https://www.linuxquestions.org/questions/linux-security-4/hide-ssh-terminal-script-from-user-4175555882/)

dewpoint 10-11-2015 06:06 PM

Hide SSH Terminal Script From User
 
Hello,

I am running the following script in /etc/bashrc to automatically record all terminal sessions to file on my server. (I regularly use contractors to install new scripts on my server, and have run into problems in the past where they have also installed disruptive scripts that redirect users, or other malicious scripts. I am hoping that by recording their activities, I can detect any malicious activities before they cause any harm).

test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f $HOME/$(date +"d-b-%y_%H-%M-%S")_shell.log)

When a user first logs in to my Linux server by ssh, they see the following:
Script started, file is /root/11-Oct-15_18-38-22_shell.log

My question is, is there any way to run this script without the user being notified that the script has been started?

Or perhaps another script that achieves the same without notifying the user?

Thanks for the help.

dewpoint 10-11-2015 09:23 PM

Figured it out. In case anyone else wants to do the same, simply add -q into the original command:

test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f -q $HOME/$(date +"d-b-%y_%H-%M-%S")_shell.log)

Sefyir 10-11-2015 09:27 PM

You might want to let them know at some point that everything they do is recorded (just a imo)

You can also do this to redirect stdout/err messages

Code:

(command; command2) &> /dev/null
won't matter what happens then, all content that would be piped out will be sent to /dev/null. This shouldn't affect recording to shell.log however.


All times are GMT -5. The time now is 11:16 PM.