ssh: execute a command before login

Martin Vegter

I am looking for a way to execute a local command when logging into a remote machine via SSH. (I want to stay logged in after the command has finished.) In other words, I want to specify the command on my command line. It should be executed on the remote machine and then I should get the shell, as if I had logged in normally.

For instance, let's say, I want to mount /home on the remote machine before I get the shell. I would do something like this (which does not work well)

ssh mymachine.example.com 'mount /home ; /bin/bash'

In effect, I am looking for a way how to condense the following two commands into one:

ssh mymachine.example.com 'mount /home'
ssh mymachine.example.com

Does anybody have any idea how to do it?

IMPORTANT: I don't want to store the command-to-be-executed on the remote machine. It must be stored locally (perhaps it contains my password to de-crypt the encrypted home.)

peterph

You are likely looking for the -t option for ssh which forces pseudo-terminal allocation - without that you are just directly connecting your terminal to standard input/output/error of the remotely running programs. Hence your command should look like this:

ssh -t mymachine.example.com 'mount /home ; /bin/bash'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to execute command before user login on linux

From Dev

Executing a remote command on SSH connection, before login

From Dev

ssh: execute command on the remote host instead of a login shell

From Dev

SSH client: port knocking (execute command before connecting)

From Dev

Azure Container Instances - from where to execute "docker login" before we execute "az container create" command

From Dev

Execute a command before shutdown

From Dev

SSH: execute sudo command

From Dev

How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

From Dev

execute command on ec2 after ssh login using bash script

From Dev

Execute command before shutdown/reboot

From Dev

Execute command before shutdown/reboot

From Java

Run ssh and immediately execute command

From Dev

ssh change user and execute command

From Dev

execute command over ssh connection

From Dev

ssh - execute complex remote command

From Dev

Execute command on successful SSH connection

From Dev

Run command on boot before login

From Dev

`ssh <host>` is a login shell, but `ssh <host> <command>` is not?

From Dev

Failed to execute, How to enter terminal before login

From Dev

How to execute a script before login screen?

From Dev

Execute a script as root on every ssh login

From Dev

ssh message after login but before password

From Dev

SSH Login "clear screen" before MOTD is displayed

From Dev

Ssh login/shell not completely working (as before)

From Dev

How to execute a command on behalf of a user if login is denied

From Dev

A robust way to execute a command/run a script at login?

From Dev

How to execute a command on behalf of a user if login is denied

From Dev

CMake: How to execute a command before make install?

From Dev

How to execute shell command before compile task?

Related Related

  1. 1

    How to execute command before user login on linux

  2. 2

    Executing a remote command on SSH connection, before login

  3. 3

    ssh: execute command on the remote host instead of a login shell

  4. 4

    SSH client: port knocking (execute command before connecting)

  5. 5

    Azure Container Instances - from where to execute "docker login" before we execute "az container create" command

  6. 6

    Execute a command before shutdown

  7. 7

    SSH: execute sudo command

  8. 8

    How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

  9. 9

    execute command on ec2 after ssh login using bash script

  10. 10

    Execute command before shutdown/reboot

  11. 11

    Execute command before shutdown/reboot

  12. 12

    Run ssh and immediately execute command

  13. 13

    ssh change user and execute command

  14. 14

    execute command over ssh connection

  15. 15

    ssh - execute complex remote command

  16. 16

    Execute command on successful SSH connection

  17. 17

    Run command on boot before login

  18. 18

    `ssh <host>` is a login shell, but `ssh <host> <command>` is not?

  19. 19

    Failed to execute, How to enter terminal before login

  20. 20

    How to execute a script before login screen?

  21. 21

    Execute a script as root on every ssh login

  22. 22

    ssh message after login but before password

  23. 23

    SSH Login "clear screen" before MOTD is displayed

  24. 24

    Ssh login/shell not completely working (as before)

  25. 25

    How to execute a command on behalf of a user if login is denied

  26. 26

    A robust way to execute a command/run a script at login?

  27. 27

    How to execute a command on behalf of a user if login is denied

  28. 28

    CMake: How to execute a command before make install?

  29. 29

    How to execute shell command before compile task?

HotTag

Archive