How can I keep a local, timestamped record of all remote commands I use in ssh (command-line openssh client started through bash)? Requirements:Essential:100% client-side without relying on server loggingConfigured or installed per-user with logs stored in the user's home directory.Support for distinguishing between multiple simultaneous sessions with various users and hosts.Non-intrusive (no need to activate it each time and does not interfere significantly with using ssh)High priority:Either output is not logged or filtered out as much as possibleEither password entries are not logged or the file is encryptedIndicates the actual commands used (after tab/ history completion, backspaces, CTRL+C, etc... have been processed)Nice to have:Also logs commands in chained sessions (commands entered during remote ssh or su <user> sessions)Session start and end should be loggedA simple bash-based, non-root solution would be best (perhaps an alias or bash wrapper script for the ssh command?)My skill level:I am not new to programming, but am still learning bash and the Linux way, so code samples with brief explanations would be most appreciated.Possible strategieskeylogger -- Problem: logs passwords, does not log tab/ history completion (see glenn's answer)screen with scrollback dumping once per second and diff between them to find new scrollback lines -- Problem: how can this be implemented in an useful automated way?ssh $@ | tee >(some_cleaner_function >> $logfile) -- Problem: cannot handle multiline commands or history in chained sessions, careful cleanup needed (see my answer)A combination of some of the aboveAn exampleThe following SSH session:user@local:~$ ssh user@remoteLast login: Tue Jun 17 16:34:23 2014 from localuser@remote:~$ cd testuser@remote:~/test$ lsa  buser@remote:~/test$ exitMight result in a log at ~/logs/ssh.log such as:2014-06-17 16:34:50   [user@remote - start]2014-06-17 16:34:51   [user@remote] cd test2014-06-17 16:34:52   [user@remote] ls2014-06-17 16:34:53   [user@remote] exit2014-06-17 16:34:53   [user@remote - end]Or, perhaps a separate log will be created for each session with the command line used to start the session at the top of the file. 
Local, timestamped logging of all ssh commands?
bash;shell;command line;openssh