How to redirect command output from remote machine to local file via ssh?

Solution 1:

Depend on your command you can do something like this:

ssh user@machine command > log

the log will be saved in your machine, a real example:

ssh [email protected] ls > log

If your command does not supports outputs to stdout then run it like this:

ssh [email protected] "command -o output; cat output"  > log

Solution 2:

If you want to see what are typing and output at the same time - try it:

ssh user@host 2>&1 | tee ssh-session.log