Is there a way to put the password directly in an ssh command?
When I connect to a machine with ssh user@host it prompts me for a password interactively. I want to run this from a script, so the prompt is a problem — the script stops and waits.
Is there a flag that takes the password on the command line, in the way some other tools accept credentials as arguments?
If there is not, what is the correct way to make this non-interactive?
@ssh_serkan · 2d ago
There is deliberately no such flag, and understanding why points straight at the right answer.
A password on a command line ends up in your shell history, in the process list where any user on the machine can read it, and often in logs. Every one of those is a place a credential should never be. The client refuses to accept one for that reason, not as an oversight.
The correct solution is public key authentication, which is easier than the workaround and better in every respect:
ssh-keygen -t ed25519to create a key pair if you do not have one. Accept the defaults.ssh-copy-id user@hostto install the public half on the server. This asks for the password once, and only once.ssh user@hostnow connects with no prompt.That is the whole procedure and it usually needs no server configuration at all. For a script, this is the answer — non-interactive, no secret on any command line, and revocable by deleting one line on the server.
Reply
Report