how to get scp logs on remote server
Basically, I want to log each and every file which is sent or received via SCP on the server.
Let say a user does a SCP from Server-1 to Server-2. I figured out the way to get logs on senders side, but how to get what is been transferred on the receiver's side?
I want the logs on the receiver's side containing the names of the files which are transferred to it via SCP.
Also to get logs on senders side I am using my bash script which first save the filename to a log file and then use SCP to transfer it. Is there any better approach to do so.
Thanks in advance for any suggestion.
I just found an interesting soloution others might be interested in:
When using scp
it actually also calles the binary on the Server with the -f
flag.
This means that one can write a simple wrapper for the server-side scp
, like this:
First change your original scp
's name:
mv /usr/bin/scp /usr/bin/scp-org
Than create a simple scripte in its name:
sudo nano /usr/bin/scp
with the contents:
#/bin/bash
scp-org $@ | tee >(grep -aEo "[CD][0-7]{4} [0-9]* .*$" --line-buffered >> /var/log/scp.log)
This could of course be refined, but it works as a example.
You can now use tail -f /var/log/scp.log
and see all files beeing transfered in real time