Why can't I authenticate a curl request when piping to less or more?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












(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.










share|improve this question













migrated from serverfault.com Oct 1 '17 at 22:09


This question came from our site for system and network administrators.














  • 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














up vote
0
down vote

favorite












(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.










share|improve this question













migrated from serverfault.com Oct 1 '17 at 22:09


This question came from our site for system and network administrators.














  • 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












up vote
0
down vote

favorite









up vote
0
down vote

favorite











(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.










share|improve this question













(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.







curl pipe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 26 '17 at 21:19









spanishgum

1437




1437




migrated from serverfault.com Oct 1 '17 at 22:09


This question came from our site for system and network administrators.






migrated from serverfault.com Oct 1 '17 at 22:09


This question came from our site for system and network administrators.













  • 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
















  • 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















Have you tried it without |more ?
– Marco
Sep 29 '17 at 17:02




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




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










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










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 )





share|improve this answer
















  • 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

















up vote
0
down vote













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!






share|improve this answer
















  • 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.
    – Aaron Copley
    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







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395525%2fwhy-cant-i-authenticate-a-curl-request-when-piping-to-less-or-more%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










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 )





share|improve this answer
















  • 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














up vote
3
down vote



accepted










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 )





share|improve this answer
















  • 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












up vote
3
down vote



accepted







up vote
3
down vote



accepted






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 )





share|improve this answer












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 )






share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 1 '17 at 22:17









kasperd

2,1691925




2,1691925







  • 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












  • 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







1




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




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




This is exactly what I was looking for! This makes sense. Thank you both!
– spanishgum
Oct 2 '17 at 16:03












up vote
0
down vote













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!






share|improve this answer
















  • 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.
    – Aaron Copley
    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














up vote
0
down vote













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!






share|improve this answer
















  • 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.
    – Aaron Copley
    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












up vote
0
down vote










up vote
0
down vote









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!






share|improve this answer












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!







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 26 '17 at 21:48









alexus

443620




443620







  • 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.
    – Aaron Copley
    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












  • 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.
    – Aaron Copley
    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







1




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.
– Aaron Copley
Sep 26 '17 at 21:59




"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.
– Aaron Copley
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




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




@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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395525%2fwhy-cant-i-authenticate-a-curl-request-when-piping-to-less-or-more%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)