0

Each time I run a command like this

ssh [email protected]

I've to type in the ssh password.

Each time I run a command like this

git push origin master

(pushing code to github)

I've to type in the github password.

Is there any bash thing to write these password inline with the command?

I mean something like

git push origin master < 'mypass'

or

git push origin master | 'mypass' 
5
  • 1
    For SSH (and git actually), you can consider using key authentication instead. For git this will happen automatically if you use the SSH URL and not the HTTPS one (afaik). Anyways, this question belongs on superuser. Commented May 15, 2012 at 17:06
  • I'd recommend using PPK auth, but to answer the actual question, you can do: echo "something" | git push origin master to feed input expected by the second command. I'm not sure if it will work in this case. Commented May 15, 2012 at 17:07
  • @birryee using this command I get Pseudo-terminal will not be allocated because stdin is not a terminal. Commented May 15, 2012 at 17:13
  • 1
    In bash, there is a special syntax for this purpose. However, I doubt it works with password prompts. The syntax is gut push origin master <<< "mypass". Commented May 15, 2012 at 17:31
  • 1
    There's a reason that many programs don't accept passwords on the command line. There's a security risk from the password showing in the output of ps. Commented May 15, 2012 at 17:35

1 Answer 1

1

Use public key authentication for git hub.

For ssh-ing to the host add your key to the host's authorized_keys file(default location is the /home/<user>/.ssh directory of the user you are logging in as).

If the daemon is configured correctly it will simple use your key to authenticate before it prompts for a password.

Sign up to request clarification or add additional context in comments.

5 Comments

I dont want a way for non-typing the password. I would like to know how to insert a string after a command..
The solution also applies to your first example, ssh [email protected]. And the advice about not having your password present on the command line is still sound. If by "insert a string after a command" you mean something like "provide input to a command", comments to the question have given some examples of how to do it, though that probably won't work if you want an interactive ssh session.
@gaggina Processes, stdin and std out don't really work that way. The plumbing(at least given my understanding) bash is forking a process giving it the descriptors for input and ouput and establishing a socket. It pumps your data over the socket and sits on a listen(). The listen then writes the password prompt out to std out and sits on a poll() of the standard in waiting for you to type. All of this is a result of the first part of your piped command the second part doesn't get evaluated until it exits.
@gaggina most processes that allow passwords to be provided do so as part of their command list. This is not a good way to do things because it allows someone to get your pw by inpecting your bash history. Fixing this is one of the core use cases of public key authentication.
Thank you all for you're answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.