I need to login into multiple servers from one Unix box and need to login as a superuser account and then I need to perform some actions on the server. For this, i'll use for loop to provide the server names to the script, but for every login as a super user, it is asking user password. so when we are running the script, we are giving the password for every login.
For example, 10 servers are there to login.
To login into the server, it is not asking any passwords, but to login as a super user from the box, it is asking password. So for each box, i am providing the password 10 times.
I dont want to give the password for everytime login, How can I resolve this issue?
can anyone please provide an assistance for the same?
depending on the distribution you are using, expect is maybe part of your system already. most linux distributions are with expect by default. solaris doesn't have expect by default. i don't know how about aix and othe flavors...
you're logging into the server.. then su'ing to root? perhaps you should just setup nopasswd sudo access to the commands you need as the user you can login to with no passowrd.
If it's possible, just update your sudoers file on those servers.
username ALL=(ALL) NOPASSWDL:ALL
of course.. thats full root access to the user so you can tailor that down... but with the nopasswd: option you will not need a password.
then you can just add: sudo -u root (or whatever user you want) in front of your find/cleanup commands with no need to store the password in clear text anywhere.