tags:

views:

194

answers:

4

Hello,

I have this bash file, which asks for IP, password, etc. for OpenSSH to a device.

Now, if i use ssh root@ip, i have to enter the password. This is really irritating. Secondly; i cannot let my script send commands to it.

This is what i want->

  1. Not the password thing; i already found something; but it tells me the commands are not found?:

    #!/usr/bin/expect -f

    spawn ssh root@$IPADDR

    expect "password:"

    sleep 1

    send "$rpass\r"

    1. I want the user to be able to see some menus where it can choose from; after that; every command is done for him. So like a new window, or something like that?

    2. I do not want to use: -Any external stuff -No extra editing of the SSH connection

BASH INFO: GNU Bash, v. 4.0.33(1)-release (i486-pc-linux-gnu), running on Linux Mint. But it got to be available for serveral linux distro's, and also on Mac?

Thanks.

+2  A: 

Many tools to go great lengths to prevent what you are doing. I recommend using ssh public keys to solve this problem instead of passwords.

The big alternative is to write your own modified ssh client based on the open source so as to take control of the password management.

Oh, well, I forgot. You can probably outsmart this with a pty, since then /dev/tty will be what you control. expect might help you with this.

bmargulies
as i stated: `No extra editing of the SSH connection`; including public keys.
YourComputerHelpZ
I could start editing the ssh client, but it's going to take some time. Thanks for suggesting.
YourComputerHelpZ
+1  A: 

Use ssh-keygen to create a public key for your machine, then copy your local ~/.ssh/id_rsa.pub or ~/.ssh/identity.pub to the remote system, in ~/.ssh/authorized_keys.

You may need to tighten the permissions on the authorized_keys file: chmod 600

Nick Dixon
A: 

Expect is the usual tool for automating interactive sessions.

Dennis Williamson
i already gave this in my question, but i do not have spawn and send either. Now, i really have to download them, put in my folder? So harsh.
YourComputerHelpZ
Those are expect commands, you ARE running the script through expect, yes?
Daniel Bruce
Spawn and send are commands that `expect` recognizes. They aren't separate downloads. You need to make sure that the path to `expect` is correct for your system in the shebang. You will also probably want to use the `interact` command in your `expect` script.
Dennis Williamson
how can i use expect as something to share with others?
YourComputerHelpZ
+1  A: 

Have you considered Paramiko? It's a Python-library for interacting with SSH.

Alex Brasetvik
Can i interact with it trough bash?
YourComputerHelpZ
Depends on what you want. If you'd provided more details about what problem you're *really* trying to solve, it'd be easier to help.
Alex Brasetvik
What i try to do is using bash make a sort of ssh client. I really like this Paramiko idea; but what i need to do is interacting it with bash. The code is written in bash and i want it to keep it like that. I do not know Python; i am a beginning programmer. Anyway; what i want to do is like (almost) everything what's possible with ssh; the password thing as itś in paramiko, cd to directory; permission editing; removing files/folders; creating folders; copying files/folders from PC to Device; etc.
YourComputerHelpZ