Skip to main content
added 464 characters in body
Source Link
Reda Salih
  • 1.8k
  • 7
  • 9

I will give you an example with sshpass using a temporary fd that will be closed later, also to use the password as an argument instead of stdin wit using set -x it won't printed out the password :

#Set the password as an environment variable
export password=MyPassword
#Create the file descriptor 3 and link it to /tmp/pwd, you can use one from 3 to 9.
exec 3<> /tmp/pwd
#Copy the content of password  env variable to /tmp/pwd using dd command
dd of=/tmp/pwd <<< "$password" 
#Here using cat and passing it to xargs so stdout will be catched by stdin of xargs, then the password will be available within the second  curly brackets
cat /tmp/pwd|pwd  | xargs -I {} sshpass -p {} ssh <user>@<ip>
#Close the file descriptor
exec 3>&-
#Remove the tmp file
rm -f /tmp/pwd

You can adjust this answer to your use cases.

I will give you an example with sshpass using a temporary fd that will be closed later, also using set -x won't printed out the password :

export password=MyPassword
exec 3<> /tmp/pwd
dd of=/tmp/pwd <<< "$password" 
cat /tmp/pwd| xargs -I {} sshpass -p {} ssh <user>@<ip>
exec 3>&-
rm -f /tmp/pwd

You can adjust this answer to your use cases.

I will give you an example with sshpass using a temporary fd to use the password as an argument instead of stdin wit using set -x it won't printed out the password :

#Set the password as an environment variable
export password=MyPassword
#Create the file descriptor 3 and link it to /tmp/pwd, you can use one from 3 to 9.
exec 3<> /tmp/pwd
#Copy the content of password  env variable to /tmp/pwd using dd command
dd of=/tmp/pwd <<< "$password" 
#Here using cat and passing it to xargs so stdout will be catched by stdin of xargs, then the password will be available within the second  curly brackets
cat /tmp/pwd  | xargs -I {} sshpass -p {} ssh <user>@<ip>
#Close the file descriptor
exec 3>&-
#Remove the tmp file
rm -f /tmp/pwd

You can adjust this answer to your use cases.

added 1 character in body
Source Link
Reda Salih
  • 1.8k
  • 7
  • 9

I will give you an example with sshpass using a temporary fd that will be closed later, also using set -x won't printeprinted out the password :

export password=MyPassword
exec 3<> /tmp/pwd
dd of=/tmp/pwd <<< "$password" 
cat /tmp/pwd| xargs -I {} sshpass -p {} ssh <user>@<ip>
exec 3>&-
rm -f /tmp/pwd

You can adjust this answer to your use cases.

I will give you an example with sshpass using a temporary fd that will be closed later, also using set -x won't printe out the password :

export password=MyPassword
exec 3<> /tmp/pwd
dd of=/tmp/pwd <<< "$password" 
cat /tmp/pwd| xargs -I {} sshpass -p {} ssh <user>@<ip>
exec 3>&-
rm -f /tmp/pwd

You can adjust this answer to your use cases.

I will give you an example with sshpass using a temporary fd that will be closed later, also using set -x won't printed out the password :

export password=MyPassword
exec 3<> /tmp/pwd
dd of=/tmp/pwd <<< "$password" 
cat /tmp/pwd| xargs -I {} sshpass -p {} ssh <user>@<ip>
exec 3>&-
rm -f /tmp/pwd

You can adjust this answer to your use cases.

Source Link
Reda Salih
  • 1.8k
  • 7
  • 9

I will give you an example with sshpass using a temporary fd that will be closed later, also using set -x won't printe out the password :

export password=MyPassword
exec 3<> /tmp/pwd
dd of=/tmp/pwd <<< "$password" 
cat /tmp/pwd| xargs -I {} sshpass -p {} ssh <user>@<ip>
exec 3>&-
rm -f /tmp/pwd

You can adjust this answer to your use cases.