0

I want to use a LOCAL script to install ruby remotely on a server. Following is my code:

sshpass -p ****** ssh hx@$HOST 'bash -s' <<'ENDSSH'
    export PATH=$PATH:/home/hx/.rvm/bin/

    rvm install 2.2.0
ENDSSH

When I run this script, an error occurs saying:

Error running 'requirements_debian_update_system ruby-2.2.0',
showing last 15 lines of /home/hx/.rvm/log/1423392690_ruby-2.2.0/update_system.log
++ [[ -d /usr/sbin ]]
++ [[ :/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/hx/.rvm/bin/:/home/hx/.rvm/bin: != *\:\/\u\s\r\/\s\b\i\n\:* ]]
++ for sbin_path in /sbin /usr/sbin /usr/local/sbin
++ [[ -d /usr/local/sbin ]]
++ [[ :/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/hx/.rvm/bin/:/home/hx/.rvm/bin: != *\:\/\u\s\r\/\l\o\c\a\l\/\s\b\i\n\:* ]]
++ [[ -n '' ]]
++ command_to_run=(__rvm_sudo -p "%p password required for '$*': " "${command_to_run[@]}")
++ __rvm_sudo -p '%p password required for '\''apt-get --quiet --yes update'\'': ' apt-get --quiet --yes update
++ command sudo -p '%p password required for '\''apt-get --quiet --yes update'\'': ' apt-get --quiet --yes update
++ sudo -p '%p password required for '\''apt-get --quiet --yes update'\'': ' apt-get --quiet --yes update
sudo: no tty present and no askpass program specified
++ return 1
++ typeset __ret=1
++ case ${__ret} in
++ return 1
Requirements installation failed with status: 1.
make: *** [install-ruby] Error 1

It turns out that when running rvm install as a non-root user, it will ask you to input the password to update apt-get DURING the process.

Is there a way to automatically input the password within my script? Like

echo password | apt-get -S install xxxxxx
HanXu
  • 5,507
  • 6
  • 52
  • 76

1 Answers1

0

Generally not: sending passwords to sudo is not considered secure. The error message points to the recommended solution: provide (configure) a program which will prompt you for the password. With sudo, once you have given a valid password it remains in effect for several minutes (prolonged if you keep using the credentials before they time out).

For configuring, etc., this summary of askpass seems helpful.

Here is another summary, with an example: Graphically ask for password in a bash script and retain default sudo timeout setting. The interesting thing is that its "askpass" program is a shell script which calls kdialog. A similar example could be developed using "dialog", or even a bash script which used "read -p" to read a variable, or even -- simply echo the password as done in How to use sudo inside of a Run Script build phase in Xcode 4?

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105