# How to automatically enter password in a script?

**URL:** <https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769>\
**Category:** Shell Programming and Scripting\
**Created:** [April 7, 2015, 4:57am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769 "2015-04-07T04:57:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobochacha29](https://community.unix.com/letter_avatar/bobochacha29/32/5_5575768a8748004e209b776fc1b2916d.png) [@bobochacha29](https://community.unix.com/u/bobochacha29)\
**Post date:** [April 7, 2015, 4:57am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/1 "2015-04-07T04:57:55Z")

</div>

Hi  
I'm working with AIX 6.1  
I would like to ssh to a server without entering password ( to monitor something) but there's no way to do that by authentication keys, so I need to write a script which can ssh to that server without entering password ( no need to hide passsword in the script, just an user account to monitor ).

Can someone help me please :(:(☹

---

<div class="post-metadata">

**Author:** ![clx](https://community.unix.com/letter_avatar/clx/32/5_5575768a8748004e209b776fc1b2916d.png) [@clx](https://community.unix.com/u/clx)\
**Post date:** [April 7, 2015, 5:08am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/2 "2015-04-07T05:08:58Z")

</div>

Use `ssh-keygen` . Google or seach within the forum for more details.

---

<div class="post-metadata">

**Author:** ![bobochacha29](https://community.unix.com/letter_avatar/bobochacha29/32/5_5575768a8748004e209b776fc1b2916d.png) [@bobochacha29](https://community.unix.com/u/bobochacha29)\
**Post date:** [April 7, 2015, 5:21am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/3 "2015-04-07T05:21:13Z")

</div>

> [@clx](#):
>
> Use `ssh-keygen` . Google or seach within the forum for more details.

As I said above, the authentication keys doesn't work in this case ( actually it's because of the limit of the OS and some security reasons )

---

<div class="post-metadata">

**Author:** ![sea](https://community.unix.com/user_avatar/community.unix.com/sea/32/2946_2.png) [@sea](https://community.unix.com/u/sea)\
**Post date:** [April 7, 2015, 5:25am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/4 "2015-04-07T05:25:10Z")

</div>

For security reasons, it would make sense to enable ssh and not enforcing plaintext passwords in scripts, as THAT is a higher risk, due to the passwords beeing readable by everyone!  
Specialy, since you want to ssh on your server...

Just my 2 cents.

---

<div class="post-metadata">

**Author:** ![clx](https://community.unix.com/letter_avatar/clx/32/5_5575768a8748004e209b776fc1b2916d.png) [@clx](https://community.unix.com/u/clx)\
**Post date:** [April 7, 2015, 5:42am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/5 "2015-04-07T05:42:01Z")

</div>

> [@bobochacha29](#):
>
> As I said above, the authentication keys doesn't work in this case ( actually it's because of the limit of the OS and some security reasons )

Ah, I missed that point. You mentioned there is no option to use those! What issues you facing?

Apart from ssh-keygen, you can use `expect` .

---

<div class="post-metadata">

**Author:** ![bobochacha29](https://community.unix.com/letter_avatar/bobochacha29/32/5_5575768a8748004e209b776fc1b2916d.png) [@bobochacha29](https://community.unix.com/u/bobochacha29)\
**Post date:** [April 7, 2015, 5:51am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/6 "2015-04-07T05:51:23Z")

</div>

> [@sea](#):
>
> For security reasons, it would make sense to enable ssh and not enforcing plaintext passwords in scripts, as THAT is a higher risk, due to the passwords beeing readable by everyone!  
> Specialy, since you want to ssh on your server...
> 
> Just my 2 cents.

Because of the limit of the OS version of the server ( which can not update to a higher version ) I want to ssh, I can not ssh without password to that server by an user account ( it requires admin account ). If I could done it, I would have done it already.

So please stop talking about the ssh-keygen. :mad::mad::mad:

---------- Post updated at 04:51 AM ---------- Previous update was at 04:46 AM ----------

> [@clx](#):
>
> Ah, I missed that point. You mentioned there is no option to use those! What issues you facing?
> 
> Apart from ssh-keygen, you can use `expect` .

Could you show me detail code, because I found some examples using `expect` , but it seems not work 😕😕😕. Thank you

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/5_5575768a8748004e209b776fc1b2916d.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [April 7, 2015, 12:55pm UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/7 "2015-04-07T12:55:04Z")

</div>

Assuming that you are not using ssh at all, can I presume that rlogin would be allowed? You can grant (for a given user) the source addresses that can rlogin to it without further credentials being required.

Does that offer an option? I would try to avoid expect if possible because of the risks and complexities that it introduces.

Robin

---

<div class="post-metadata">

**Author:** ![bobochacha29](https://community.unix.com/letter_avatar/bobochacha29/32/5_5575768a8748004e209b776fc1b2916d.png) [@bobochacha29](https://community.unix.com/u/bobochacha29)\
**Post date:** [April 8, 2015, 3:52am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/8 "2015-04-08T03:52:28Z")

</div>

> [@rbatte1](#):
>
> Assuming that you are not using ssh at all, can I presume that rlogin would be allowed? You can grant (for a given user) the source addresses that can rlogin to it without further credentials being required.
> 
> Does that offer an option? I would try to avoid expect if possible because of the risks and complexities that it introduces.
> 
> Robin

I would like to write a script to connect from an AIX server to a SAN switch running FabOS 6.4 ( which can't upgrade to version 7 ) to monitor somethings. FabOS version 7 has a feature allowing an admin account to import authentication key for any users, but FabOS 6 doesn't. In FabOS 6, an admin account can import authentication key for only itself. It means that if I connect to that SAN switch using ssh-keygen, I'll have to login directly to an admin account, and this isn't my choice. I just want to do this by an user account.

Not using ssh-keygen means that each time I run the script, I have to enter the password. It's the problem I'm facing :(:(:(.

---

<div class="post-metadata">

**Author:** ![Peasant](https://community.unix.com/user_avatar/community.unix.com/peasant/32/2251_2.png) [@Peasant](https://community.unix.com/u/Peasant)\
**Post date:** [April 8, 2015, 5:45am UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/9 "2015-04-08T05:45:27Z")

</div>

As i see in documentation, you can create a user with admin role for which you can use ssh keys.

"The default admin user must set up the allowed-user with the admin role."

I haven't done this myself, but i suspect that admin role for user will be able to fulfill your request regarding "monitoring somethings"

Hope the helps.

Regards  
Peasant.

---

<div class="post-metadata">

**Author:** ![bobochacha29](https://community.unix.com/letter_avatar/bobochacha29/32/5_5575768a8748004e209b776fc1b2916d.png) [@bobochacha29](https://community.unix.com/u/bobochacha29)\
**Post date:** [April 13, 2015, 11:52pm UTC](https://community.unix.com/t/how-to-automatically-enter-password-in-a-script/351769/10 "2015-04-13T23:52:19Z")

</div>

> [@peasant](#):
>
> As i see in documentation, you can create a user with admin role for which you can use ssh keys.
> 
> "The default admin user must set up the allowed-user with the admin role."
> 
> I haven't done this myself, but i suspect that admin role for user will be able to fulfill your request regarding "monitoring somethings"
> 
> Hope the helps.
> 
> Regards  
> Peasant.

As what I read. there's no option to do that in FabOS, admin is admin.
