A wizard did it :donor: 🇨🇦 on Nostr: Better programmers than me, show me a less sketchy way to do this. I'm trying to make ...
Better programmers than me, show me a less sketchy way to do this. I'm trying to make a bash script that will copy a file to a machine, then ssh into it and run a list of commands as sudo. All of these use password authentication (I know, don't ask), and I cannot login as root. I cannot think of a way to pass the password through the ssh tunnel so that it can be read on the other side. All I've come up with so far is to do this:#!/bin/bash<br>servers=$(cat servers.txt)<br>for cpu in $servers; do<br>ssh -t $cpu << 'EOF'<br>echo "[SUDO PASSWORD]" > ./pass<br>cat pass | sudo -S [all the rest of my commands here]<br>rm ./pass<br>exit
This works, but oh baby is that a sketchy way to do things and there has to be a better solution to this.
#bash #linux
Published at
2026-02-19 23:40:17 UTCEvent JSON
{
"id": "f9c037088a157c30133b05e46e2562c19581c978bbef7c671bf084d13635f651",
"pubkey": "4607fc079f2a7980dc16443133cc2ac18fb2cf84a91c381c6d81663cd0851f9f",
"created_at": 1771544417,
"kind": 1,
"tags": [
[
"t",
"linux"
],
[
"t",
"bash"
],
[
"proxy",
"https://infosec.exchange/@Mustardfacial/116099934922272102",
"web"
],
[
"proxy",
"https://infosec.exchange/users/Mustardfacial/statuses/116099934922272102",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://infosec.exchange/users/Mustardfacial/statuses/116099934922272102",
"pink.momostr"
],
[
"-"
]
],
"content": "Better programmers than me, show me a less sketchy way to do this. I'm trying to make a bash script that will copy a file to a machine, then ssh into it and run a list of commands as sudo. All of these use password authentication (I know, don't ask), and I cannot login as root. I cannot think of a way to pass the password through the ssh tunnel so that it can be read on the other side. All I've come up with so far is to do this:#!/bin/bash\u003cbr\u003eservers=$(cat servers.txt)\u003cbr\u003efor cpu in $servers; do\u003cbr\u003essh -t $cpu \u0026lt;\u0026lt; 'EOF'\u003cbr\u003eecho \"[SUDO PASSWORD]\" \u0026gt; ./pass\u003cbr\u003ecat pass | sudo -S [all the rest of my commands here]\u003cbr\u003erm ./pass\u003cbr\u003eexit\n\n\n\nThis works, but oh baby is that a sketchy way to do things and there has to be a better solution to this. \n\n#bash #linux",
"sig": "389c2ea650edc07965e21183fc88fd1705541083c2f8cbbe94dd17c98a2e13c846b8924658ac75308ad0a2d3b8536de16f7c27d07c3f6345e130e4d11365db84"
}