I was trying to use "su - <account>" but it prompts me for password in interactive mode. How do I write main.sh script that executes various commands by logging in as different accounts and login profiles. Is there a way to automatically redirect the password for "su" command to accept the password.
It is very difficult to redirect a password into su and this is intentional. Storing passwords and automatically logging into accounts is very dangerous and often a bad idea.
sudo can be configured to login without passwords, it is very flexible; but be careful to only give such permissions in a very limited and specific way.
But could you please be a little more descriptive about how to use ssh with key-based authentication as I tried manning it and searching it in google but was unable to implement the same in my script.
So ,could you please elaborate a little more about this procedure.
ant:/rdm/users/jju $ remsh ant -l vbe
Please wait...checking for disk quotas
(c)Copyright 1983-2000 Hewlett-Packard Co., All Rights Reserved.
(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California
(c)Copyright 1980, 1984, 1986 Novell, Inc.
(c)Copyright 1986-1992 Sun Microsystems, Inc.
(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology
(c)Copyright 1989-1993 The Open Software Foundation, Inc.
(c)Copyright 1986 Digital Equipment Corp.
(c)Copyright 1990 Motorola, Inc.
(c)Copyright 1990, 1991, 1992 Cornell University
(c)Copyright 1989-1991 The University of Maryland
(c)Copyright 1988 Carnegie Mellon University
(c)Copyright 1991-2000 Mentat Inc.
(c)Copyright 1996 Morning Star Technologies, Inc.
(c)Copyright 1996 Progressive Systems, Inc.
(c)Copyright 1991-2000 Isogon Corporation, All Rights Reserved.
RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure by the U.S. Government is subject to
restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
Technical Data and Computer Software clause in DFARS 252.227-7013.
Hewlett-Packard Company
3000 Hanover Street
Palo Alto, CA 94304 U.S.A.
Rights for non-DOD U.S. Government Departments and Agencies are as set
forth in FAR 52.227-19(c)(1,2).
You have mail.
ant:/home/vbe $
ant:/home/vbe $ exit
logout
Connection closed.
ant:/rdm/users/jju $ id
uid=6206(jju) gid=20(users)
Thxs for the reply.
I tried configuring .rhosts file according to my requirements but I am not authorised to add or modify anything into the same as I am not a root user.
The ssh and remsh solutions will not work unless you have access to the other accounts or root access. Can you not login as the other accounts and configure the authorized_keys files or the .rhosts files?
Of course you can since you know the other account and have its passwd
( you connect as, then edit/create .rhosts there is not need to be root here...)