Linux Auto bash login

Discussion in 'Software' started by DougEdey, 8 Sep 2006.

  1. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    Right, this may be slightly confusing, and probably one for Glider.

    I need to be able to login to a linux system, run a command and log off again.

    But it must be done using no user input, and preferably on one line.

    I have looked at SU but it requires password to be input and I can't work out how todo that automatically.

    Any ideas?
     
  2. trigger

    trigger Procrastinator

    Joined:
    22 Mar 2004
    Posts:
    1,097
    Likes Received:
    30
    How about using SSH keys (or are we not talking remote here?) to log in automatically, then specifying what to run, so:

    Code:
    $ ssh user@machine script_to_run
    Where you have user's public ssh key stored locally.
     
  3. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    it is remote, but it isn't at the same time.

    Its so I can run a command from php using exec() to get SVN details.

    At the moment I am relying on data in an SQL database.
     
  4. Glider

    Glider /dev/null

    Joined:
    2 Aug 2005
    Posts:
    4,173
    Likes Received:
    21
    I'd do it the way trigger suggested, through the use of shared keys. That way you can just ssh without it asking for a password. You can use it on a localhost too IIRC. So
    Code:
    ssh user@localhost script
    will work too. Here you have a guide on how to set it up.

    You probably don't want it to have root priveleges, so su is out ;)
     
  5. Elv13

    Elv13 What's a Dremel?

    Joined:
    26 Apr 2006
    Posts:
    107
    Likes Received:
    0
    int main()
    {
    execlp("login", "login", "-f", "username", 0);
    }


    remplae username
    compile using
    gcc file.c -o autologin
    move it to /sbin, /bin /usr/bin or where you like (in a bin folder)
    repair permissions
    chmod 755 /sbin/autologin

    and make a small script for the commant you want to use

    #/bin/sh
    /sbin/autologin
    <the command>
    exit

    save (change location of the next command to fit) and repair permission
    chmod 755 /usr/local/script/srcipt.sh


    then run when you want
    /usr/local/script/srcipt.sh
     
  6. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    Cheers, I'll have a word with the admin see if I can do that.
     
  7. Elv13

    Elv13 What's a Dremel?

    Joined:
    26 Apr 2006
    Posts:
    107
    Likes Received:
    0
    i use that for remplace xdm/gdm/kdm to save few second

    i dont think it is possible but someone know how tu use that before then end of boot time
    i made a rc init.d script but it fail if it is not the last to run. Is there a way to startX before the end of boot time (in parallel) without kdm or gdm (xdm dont have autologin...)
     
Tags:

Share This Page