the accepted answer works for executing a simple command but not for executing somewhat more complex commands (for example multiple commands using the "&&" operator). In that case it may be needed to invoke the command using "sudo" and a shell invocation, e.g.:
ssh -t root@my.machine sudo -- "screen bash -c 'test -e /var/log/messages && tail -f /var/log/messages'"
or only using a shell invocation:
ssh -t root@my.machine 'screen bash -c "test -e /var/log/messages && tail -f /var/log/messages"'
you may also consider adding an "exec bash" at the end to keep the session open afterwards, e.g.:
ssh -t root@my.machine 'screen bash -c "test -e /var/log/messages && tail /var/log/messages ; exec bash"'
if you just want to create the remote screen session and immediately detach from it afterwards you may also consider using the screen options "-d -m", e.g.:
ssh -t root@my.machine sudo -- "screen -S test123 -d -m bash -c 'test -e /var/log/messages && tail -f /var/log/messages'"
you can later on reattach to the remote screen session using:
ssh -t root@my.machine 'screen bash -c "screen -x test123 ; exec bash"'
The screen option "-S test123" is used to name the session and option "-x test123" to reattach to the session.