ssh_config: specify command to be executed on the remote machine upon login
RequestTTY yes
RemoteCommand screen -UDr
This was added in OpenSSH 7.6:
add RemoteCommand option to specify a command in the ssh config file instead of giving it on the client's command line. This allows the configuration file to specify the command that will be executed on the remote host.
ref: https://www.openssh.com/txt/release-7.6
This question has been asked before on SuperUser. The first answer uses a remote file that doesn't fit your requirements, but the second answer that suggests to use a local alias could be the solution to your problem.
It is importand that the command-to-be-executed be stored on the local machine, as it will contain password to open an encrypted disk. That is the reason why I cannot put the command into .profile on the remote machine.
This is probably not safe. If I use an echo
command as a ssh command, it shows up in ps
on the remote server:
martin@martin ~ % ssh dev2 "echo hello; ps aux|grep echo"
hello
root 25358 0.0 0.0 5848 1296 ? Ss 11:27 0:00 bash -c echo hello; ps aux|grep echo
root 25362 0.0 0.0 5012 828 ? S 11:27 0:00 grep echo