33

My internet connection is provided by the university. It is protected to a username/password combination. This means when I start up my computer, I have to start a web browser and open an arbitrary website. I am then redirected to a page, which (among other things) contains two forms. In these I have to input username and password. I managed to do this with firefox (which can save the password) and also with links (which loads faster and from the command line).

Is there any way to automate the login process using a bash script? This would allow doing the login when booting, so that it is already there when I start the X server.

3
  • 1
    You might be able to call the login script from the form's ACTION attribute with curl directly.
    – terdon
    Sep 4, 2013 at 12:56
  • Many Universities also offer a network that uses "Enterprise Authentication" (i.e. using a username/password for the network connection itself, instead of waiting until you try to access a page to ask for credentials). The ability to store such network credentials is built in the OS. It's also much more secure because it means that it's harder for others to snoop on your connection. If your University supports that, you should switch to it.
    – Moshe Katz
    Sep 9, 2013 at 19:58
  • It would also help us if you can give an (anonymized) example of the URL you are redirected to when you log in. (Anonymized here means that you should remove your MAC Address and/or IP address from the URL if they are there, but leave everything else, including the name of the University.)
    – Moshe Katz
    Sep 9, 2013 at 20:03

6 Answers 6

21

You can try it out with curl, you can Simply use curl like this to login to web page :

curl --user name:password http://somesite.com -v 

You can pass Data to website like this from Stackoverflow answer

    curl -b cookies.txt -c cookies.txt --data "Username=xx&Password=xx&Login=Login" [urlthatyour form submits]

you need cookies if you want to make another curl request after logging in. the session id in cookies will help next curl request authorized.

If you don't want cookies you can use

curl --data "Username=xx&Password=xx&Login=Login" [url that your form submits]

You can additionally refer here for Special Commands

3
  • 1
    I am not able to try this right now, but I expect that this will only work when there is a dialog box asking for the password when opening the site. In my case there are just two forms. One for the name and one for the password. I will change the question to make this clearer.
    – Tim
    Sep 4, 2013 at 12:33
  • @Tim added how to pass data,normally You would need to find out what page the page requests to (or the action value of the page). Sep 4, 2013 at 14:03
  • This sounded as if it could work, but sadly it didn't. When looking at the output of curl suggests that the Username field is correctly filled with the correct value, but the Password field is not (this may be correct as a security measure). I am not sure if the submit button was actually triggered. Does it matter what value is passed to Login?
    – Tim
    Sep 6, 2013 at 14:07
7

I finally found a way to automatically log in using elinks. It works and it is even easy to configure!

Two options need to be set. This can done by adding the following lines in ~/.elinks/elinks.conf (if the file is not there, create one) or by changing the values at the respective positions in the options dialog within elinks:

    # Save username and password for later use
set document.browse.forms.show_formhist = 1
    # Do not ask for confirmation before a form is submitted
set document.browse.forms.confirm_submit = 0

Steps for a scriptable autologin are then:

  • Set those two options
  • Open the login page in elinks, fill the forms and submit them.
  • Choose to remember name and password for later use.
  • Close elinks
  • Run elinks -auto-submit http://somesite.com

The latter command should perform the automatic login without further user interaction.

I actually use timeout 1m elinks -auto-submit http://somesite.com &, so that I do not have an idling elinks process running in the background all the time.

3

A simple way to script this is with Selenium.

You can use their Firefox "Test Recorder" plugin to record a test of yourself logging in to the network, and then play back the test.

1

Yes, there is a very simple way to login to your university's internet.You can use the 'Lynx' web browser which is a text-based browser, designed for use on terminal. So, here is the way:

$ echo "username=myname&password=mypassword" | lynx "url of the form" -post_data

where, 'username' is the name of the field corresponding to the user name in the form and 'password' is the name of the field corresponding to the password field and 'myname' and 'mypassword' are the corresponding values to be filled in the form. You can find field name by using 'Inspect Element' from any browser. I tried with curl as directed in the answer by BlueBerry - Vignesh4303 but didn't work.

0

You can get an add-on for your browser which will auto log-in to websites with saved passwords. I used AutoAuth with firefox. Then you login once and save your credentials, then write a script that just has

#!/bin/bash
firefox https://website address goes here

When executed, it will go and auto login. I tried with multiple sites and it worked well.

-1

to access quicker to your login url web without remembering username or password

#make a script below

echo "username" |xclip -sel clip |chromium-browser (input url address for login here https://...)

sleep 5

echo "password" |xclip -sel clip


Explanation of the script above

  1. echo "username" |xclip -sel clip <-- will copy to clipboard your username

  2. .... |chromium-browser` (input url address for login https://...) <-- the second part of the first line will open the login url https://.... in the chromium browser.

or open with another version of google chrome browser use below command:

google-chrome (input url address for login https://...)

to open in firefox

firefox (input url address for login https://...)

  1. sleep 5 <------ will wait for 5 seconds until execute the next command

In sleep 5 seconds can be arrange longer if the usual login loading in browser will take more than 5 seconds

  1. echo "password" |xclip -sel clip <---- will copy the password in clipboard

So When the command is executed:

  1. it will copy username in the clipboard

  2. will open the url login to the browser

  3. if cursor already in the login box, press in keyboard Ctrl-v to paste the username

  4. wait for 5 seconds (usually i count 1, 2, 3 .. to 10)

  5. tab to the password box and Ctrl-V will input the password

  6. press enter to login.


To make it simple you can separately make a script for the copy to clipboard command as explain on my other tutorial below.

https://hopelinux.blogspot.com/2022/05/copy-to-clipboard-from-command-line.html

1
  • Hi @Joe. Welcome to superuser. It is generally not a good idea, to pass around passwords via the shell (in this case even using echo). All other processes and users can see them e.g. via top or ps without needing special permissions. The clipboard can also be easily monitored from other programs...
    – Tim
    May 16, 2022 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .