I am trying to write a script which is saving the credentials to a .netrc file and then it is reading from the file in order to pass them to a curl command and saves the returned cookie file for future use. I am interested if this is secure way to pass the username and password and if there is a man in the middle attack would they be able to sniff the credentials if the server which I am trying to reach is over HTTP.
#!/bin/bash
IP="192.168.0.1"
user="Administrator"
pass="Password1234"
function credentials {
mkdir "${HOME}"/.netrc
rm "${HOME}"/.netrc/credentials.txt
touch "${HOME}"/.netrc/credentials.txt
{ echo "machine ${IP}"; echo "login ${user}"; echo "password ${pass}"; } >> "${HOME}"/.netrc/credentials.txt
chmod 600 "${HOME}"/.netrc/credentials.txt
}
function cookie {
curl -v -c cookie.txt -n "${HOME}"/.netrc/credentials.txt http://"${IP}"/setup.php
}
credentials
cookie
I have checked and the credentials.txt file is properly saved in the corresponding directory and the credentials have the right permissions, but when I try to run the cookie function, I got the following error:
't find host 192.168.0.1 in the .netrc file; using defaults
. Why curl is not able to fetch the configured username and password from the credentials.txt file?
Asked by Georgi Stoyanov
(860 rep)
Mar 5, 2018, 01:14 PM
Last activity: Oct 28, 2021, 11:43 AM
Last activity: Oct 28, 2021, 11:43 AM