Advertisement
Guest User

Untitled

a guest
Mar 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. SSH_CMD=${SSH_CMD:=ssh}
  4. SSH_USER=${SSH_USER:=USER}
  5. SSH_PASSWORD=${SSH_PASSWORD:=fakepassword}
  6. SCRIPTDIR=$(dirname $0)
  7.  
  8. trap cleanup INT TERM EXIT
  9.  
  10. askpass() {
  11. echo $SSH_PASSWORD
  12. }
  13.  
  14. cleanup() {
  15. rm $SSHCFG
  16. }
  17.  
  18. if [ -z "$SSH_USER" ]; then
  19. echo Could not obtain username from SSH_USER>&2
  20. exit 1
  21. fi
  22.  
  23. # when ssh run the SSH_ASKPASS command, it will have itself in the SSH_ASKPASS environment variable. we can detect which type of "invokation" we're in
  24. if [ -z "$SSH_ASKPASS" ]; then
  25. # DISPLAY isn't used and its content is irrelevant. but ssh requires it to be set
  26. export DISPLAY="dummy:0"
  27. # set the script to run to ourselves. this will hit the second branch of the if block
  28. export SSH_ASKPASS=$0
  29.  
  30. if [[ "$SSH_CMD" == "ssh" ]]; then
  31. setsid $SSH_CMD -F $SSHCFG -l $USER "$@"
  32. else
  33. echo "Note: Not using ssh command, make sure you're using the username $USER" >&2
  34. setsid $SSH_CMD "$@"
  35. fi
  36. else
  37. askpass
  38. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement