0

I have the following situation. I am able to ssh into a server but it requires 2FA each time I ssh into the server. Let's say that I do not have control over the server's configuration to disable/bypass 2FA. After successfully ssh'ing into the server, I am free to run commands on that server through my local terminal.

I can also run sshfs to mount a directory on my local machine with a directory on the server (this will trigger 2FA once):

$ sshfs <server>:/a/b/c /my/local/folder 

I would like to be able to run a script locally from my machine which invokes commands on the SSH server. I would not like to run the script inside the server. For example, my script may do something like the following, executed locally:

$ ssh <server> <command 1>
$ ssh <server> <command 2>
...
$ ssh <server> <command X>

However, each time the script runs a ssh command, it will trigger 2FA. I would like to avoid the 2FA completely, if possible. Ideally, I would like to encounter the 2FA once per day. Is there any way that I can leverage the sshfs mount and piggyback the session to send ssh commands to the host? I am open to other extreme alternatives as well (e.g. sending key strokes to the window of my local ssh terminal)

code
  • 101
  • 1
  • "I would not like to run the script inside the server" - why? This seems like the obvious solution. – Panki Feb 03 '23 at 09:12

0 Answers0