UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2008-11-18 07:20 PM

ramchandar
Member
From: INDIA
Registered: 2004-11-14
Posts: 33

Re: automate login

Hi,
I want to do  automated way of login to UNIX box.

#!/bin/ksh
#Script 1
su - user1 << EOF
mypass
EOF

How we do "su" through a co process

Thanks
Ram


RAMCHANDAR

[email][email protected][/email]

Offline

#2 2008-11-18 09:59 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: automate login

Offline

#3 2008-11-19 04:34 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: automate login

That is a very insecure solution as your password will be in plain text somewhere.

Probably better solution, depending on what you want:

#include <unistd.h>

int main(void){
	setuid(0);
	return execlp("login", "login", "-f", "NAME", NULL);
}

And make it setuid root if you want to run it as another user.

Or run login with the -f option directly if possible.

(I run the above prog at system startup from init to get automatically logged in.
It was needed because agetty only runs one prog and can't pass arguments.)

Offline

#4 2008-11-19 07:05 AM

ramchandar
Member
From: INDIA
Registered: 2004-11-14
Posts: 33

Re: automate login

Hi,

i dont think i can have expect on the system(AIX).I prefer to use C then expect .But again is it possible with perl ?

My constraints are i will be doing

1. su "some other user"
2.give the password
3."some other user" profile will get executed and that inturn ask for some input (hope this is on STDIN and not on tty)
4.Finally reach the prompt

All the above need to be done by connecting to another machine

Please suggest me on how to proceed


RAMCHANDAR

[email][email protected][/email]

Offline

#5 2008-11-19 03:02 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: automate login

Offline

#6 2008-11-20 03:06 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: automate login

Depends. If your login password is only used for your account and nothing else, it
doesn't matter. But if you use that password for anything else as well then it's more
secure. Sure, you're not supposed to reuse passwords, but life is too short... ;-)

Using "sudo su username" to login as someone else works too of course, but he was
talking about autologin, and I'd expect that sudo su doesn't work from a script.
You're right that using sudo is better than making the thing setuid root though.

Offline

#7 2008-11-20 02:10 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: automate login

Offline

#8 2008-11-21 01:15 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: automate login

Offline

#9 2008-11-21 02:19 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: automate login

Offline

Board footer

Powered by FluxBB