Q:

How to accpeting password by shell script

As we know that, password must be inputted while switching user [Username: test, Password: test]
[user1@hosts ~] $ su test
Password: 
[test@hosts ~]$ 

Now I want to create a shell script (example: login.sh) to switch user without entering password. 
My shell script is:
su - test
test   # The password of user test

But it still needs password entering. 
How can the shell script accept the password? 
Thanks in advance!! 

A:

Actually, I found another method to switch the user without password (Even if the new user needs password authentication). 
That is using ssh
Alias file in user1:
alias tt="ssh test@127.0.0.1"

And cat the user1's id_rsa.pub to test's authorized_keys:
user1:

user1: create ssh public key: rsa_id.pub

$ ssh-keygen -t rsa
press yes if asking...

upload the user1's public key to test's directory (this step needs input the password):

$scp id_rsa.pub test@127.0.0.1:/home/test

add the rsa_id.pub into .ssh/authorized_keys

$ su - test
Password
$ cd $ cat rsa_id.pub >> .ssh/authorized_keys
$ chmod 644 .ssh/authorized_keys

Then switch user by using tt
$ tt
Last login: Mon Jan 28 20:27:34 2013 from localhost
[test@host ~]$

