sendInput not working with ssh #21998

Closed
opened 2026-01-31 08:00:25 +00:00 by claunia · 3 comments
Owner

Originally created by @CodeDok on GitHub (Jul 23, 2024).

Windows Terminal version

1.20.11781.0 and 1.21.240626002-preview

Windows build number

10.0.19045

Other Software

OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2

Steps to reproduce

Install SSH Server (optional)

For Testing: WSL2 with OpenSSH

sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
ip address show

JSON (Fragment)

Profile

{
    "name": "wsl",
    "commandline": "ssh <user>@<ip of wsl>"
}

Action (in Fragment if preview version)

        {
            "command": {
                "action": "multipleActions",
                "actions": 
                [
                    {
                        "action": "newTab",
                        "profile": "wsl",
                        "tabTitle": "Test"
                    },
                    {
                        "action": "sendInput",
                        "input": "<password>"
                    }
                ]
            },
            "name": "wsl"
        },

Unfortunately I don't know how to send an ENTER but when I manually press ENTER there is no input from sendInput because nothing was inserted into the password field.

It's just an example for those questioning the sendInput with a password. If I want to send other inputs like sourcing an custom bashrc into an ssh session established via keys it also does not work.

Would be a nice addition to know whether its possible to press ENTER in an sendInput. I have not really found a source for reliable keypresses. I tried a few ASCII Escape Sequences from https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797, but not much luck except for the arrow keys.

Thank you very much!

Expected Behavior

It inserts the sendInput value into the terminal like it's typed by an keyboard.

Actual Behavior

Does nothing

Originally created by @CodeDok on GitHub (Jul 23, 2024). ### Windows Terminal version 1.20.11781.0 and 1.21.240626002-preview ### Windows build number 10.0.19045 ### Other Software OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 ### Steps to reproduce # Install SSH Server (optional) ## For Testing: WSL2 with OpenSSH ```batchfile sudo apt install openssh-server sudo systemctl enable ssh sudo systemctl start ssh ip address show ``` # JSON (Fragment) ## Profile ```json { "name": "wsl", "commandline": "ssh <user>@<ip of wsl>" } ``` ## Action (in Fragment if preview version) ```json { "command": { "action": "multipleActions", "actions": [ { "action": "newTab", "profile": "wsl", "tabTitle": "Test" }, { "action": "sendInput", "input": "<password>" } ] }, "name": "wsl" }, ``` Unfortunately I don't know how to send an `ENTER` but when I manually press `ENTER` there is no input from sendInput because nothing was inserted into the password field. It's just an example for those questioning the sendInput with a password. If I want to send other inputs like sourcing an custom bashrc into an ssh session established via keys it also does not work. Would be a nice addition to know whether its possible to press `ENTER` in an sendInput. I have not really found a source for reliable keypresses. I tried a few ASCII Escape Sequences from https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797, but not much luck except for the arrow keys. Thank you very much! ### Expected Behavior It inserts the sendInput value into the terminal like it's typed by an keyboard. ### Actual Behavior Does nothing
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 08:00:25 +00:00
Author
Owner

@lhecker commented on GitHub (Jul 23, 2024):

Actions are executed one after another without waiting on anything. Without having debugged this, I suspect what happens is that by the time the sendInput action runs, newTab hasn't actually finished setting up the tab yet. As such the input gets lost. We could consider fixing this, because it's probably possible to set up the connection synchronously.

To answer your other question: The "enter key" is actually the key on your numblock (bottom right). The correct name for the one in the middle of the keyboard is technically the "return key". As the name indicates, the character that the return key sends is the carriage return \r. The solution is to use "input": "<password>\r".

But please do not put your SSH password in your settings file and especially not in a sendInput action. That's simply not safe. ~/.ssh is certainly already guarded by pretty much every AV scanner on the market, whereas our settings directory most likely isn't. Instead, use SSH keys if you can (preferably Ed25519). If you need help setting up a ssh key pair, please let me know. (You should find plenty instructions on the internet already though.)

@lhecker commented on GitHub (Jul 23, 2024): Actions are executed one after another without waiting on anything. Without having debugged this, I suspect what happens is that by the time the sendInput action runs, newTab hasn't actually finished setting up the tab yet. As such the input gets lost. We could consider fixing this, because it's probably possible to set up the connection synchronously. To answer your other question: The "enter key" is actually the key on your numblock (bottom right). The correct name for the one in the middle of the keyboard is technically the "return key". As the name indicates, the character that the return key sends is the carriage return `\r`. The solution is to use `"input": "<password>\r"`. But *please* do not put your SSH password in your settings file and especially not in a sendInput action. That's simply not safe. `~/.ssh` is certainly already guarded by pretty much every AV scanner on the market, whereas our settings directory most likely isn't. Instead, use SSH keys if you can (preferably Ed25519). If you need help setting up a ssh key pair, please let me know. (You should find plenty instructions on the internet already though.)
Author
Owner

@CodeDok commented on GitHub (Jul 23, 2024):

Thank you for the enter key!

That would make sense if the actions are not dependent on the outcome of the previous action. Do you know whether it is even possible to check the completion state or result of an executed action?

Definitely do not persist any password as clear text in any config files! I just used it as a relatively easy example to reproduce the behaviour. :)

Not quite sure how we should proceed. Should I create a feature request or should we keep it as bug?

@CodeDok commented on GitHub (Jul 23, 2024): Thank you for the enter key! That would make sense if the actions are not dependent on the outcome of the previous action. Do you know whether it is even possible to check the completion state or result of an executed action? Definitely do not persist any password as clear text in any config files! I just used it as a relatively easy example to reproduce the behaviour. :) Not quite sure how we should proceed. Should I create a feature request or should we keep it as bug?
Author
Owner

@zadjii-msft commented on GitHub (Jul 23, 2024):

We don't need to keep this open, we've already got: /dip #13444

Thanks!

@zadjii-msft commented on GitHub (Jul 23, 2024): We don't need to keep this open, we've already got: /dip #13444 Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21998