Search code examples
unixsshssh-keysopenssh

Is it possible to execute commands on the LOCAL host after an SSH connection


I have a use case where I want a user to connect to a target host via SSH but I do not want to leave the private key behind (the private key is retrieved via an API)

Is this possible via openSSH or once the user ssh's to the target system can we no longer execute commands on the original host?


Solution

  • The option LocalCommandcan be used

    ssh user@host -o LocalCommand="echo hello > test.tmp"
    

    Or in your case

    ssh user@host -o LocalCommand="rm ~/.ssh/onetime_id_rsa"