0

(CentOS 7)

When I try a curl command like curl -u elastic -X GET 'http://localhost:9200/*' | more, I find that after typing only a single letter, the command executes as if I have pressed enter, and fails to authenticate.

Is this normal?

I can redirect to a file, or just scroll up, maybe even use wget (haven't tried), or even put my password in the command, but I would like to know what's going on here.

2
  • Have you tried it without |more ?
    – Marco
    Sep 29 '17 at 17:02
  • yes, it works fine without piping, and both with head or tail. It does not work with more or less.
    – spanishgum
    Sep 29 '17 at 19:09
3

The problem is that curl and more are both reading from the same TTY at the same time. Moreover they are probably both changing the TTY settings; curl because the password you type shouldn't be shown on the screen. And more because it needs character based input rather than the default line based input.

To prevent that from happening I think you just need to delay starting the more command until the curl command has started producing output. I don't know of a standard command to do that, but it can be done with two lines of Python code.

#!/usr/bin/python
import select
select.select([0], [], [])

With the above Python script you can then try this variation of the original command:

curl -u elastic -X GET 'http://localhost:9200/*' | ( ./wait.py ; more )
2
  • 1
    curl -u .... | { sleep 20 ; less ; } would give you 20 seconds to type the password before less started to read the terminal.
    – icarus
    Oct 2 '17 at 0:34
  • This is exactly what I was looking for! This makes sense. Thank you both!
    – spanishgum
    Oct 2 '17 at 16:03
0

per

# curl --help | grep -- ' -u'
 -u, --user USER[:PASSWORD]  Server user and password
# 

try:

curl --silent --user elastic:changeme --request GET localhost:9200/*?pretty | more

yet another solution:

# pass=changeme
# curl -I -u alexus:$pass https://X.X.X
HTTP/1.1 200 OK
Server: nginx/1.13.5
Date: Wed, 27 Sep 2017 17:27:19 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 2350
Connection: keep-alive
Accept-Ranges: bytes
Cache-Control: max-age=31536000
Last-Modified: Sun, 13 Aug 2017 18:21:51 GMT
Strict-Transport-Security: max-age=15768000

# 

one can also store pass variable inside of a file (don't forget to chmod 700 that file) and use source to read variable before running curl.

voila!

3
  • 1
    "or even put my password in the command, but I would like to know what's going on here" -- I think OP knows that's an option, but would prefer not to do this. Sep 26 '17 at 21:59
  • Indeed. I don't want to see my password saved into my history (especially when I jump into root). I saw a gpgkey technique that could avoid this, but I still want to know why this happens out of curiosity.
    – spanishgum
    Sep 27 '17 at 15:12
  • @spanishgum take a look at my updated answer for alternative ways to not to save password in a history.
    – alexus
    Sep 27 '17 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.