Bash: SSH Management

I have this bash file that requests IP, password, etc. for OpenSSH on the device.

Now, if I use ssh root@ip , I have to enter the password. This is really annoying. Secondly, I cannot let me send script commands.

This is what I want →

  • Not a password thing; I already found something; but he tells me no teams were 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 from which he can choose; after that; every team is done for him. So how about in a new window or something like that?

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

BASH INFO: GNU Bash, v. 4.0.33 (1) -release (i486-pc-linux-gnu) running on Linux Mint. But should it be available for several Linux distributions, as well as on a Mac?

+8
bash ssh controls
source share
8 answers

Lots of tools to help you do what you do. I recommend using ssh public keys to solve this problem instead of passwords.

A great alternative is to write your own open source modified ssh client to take password management.

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

+3
source share

The correct way to do this without storing passwords in clear text on your computer using ssh. First start:

SSH keygen

This will create a new SSH key in ~/.ssh/id_rsa.pub . After that, just run:

ssh-copy-id user@my.server.com

If you are on OS X or another computer that does not have "ssh-copy-id", there are single-line alternatives , such as:

cat ~ / .ssh / id_rsa.pub | ssh user @machine "mkdir ~ / .ssh; cat → ~ / .ssh / authorized_keys"

Ultimately, you just need to add the contents of ~/.ssh/id_rsa.pub on your local machine to ~/.ssh/authorized_keys on the remote server. As you do this, you do this simply by using the keyboard shortcuts for this.

+15
source share

Expect is a common tool for automating interactive sessions.

+2
source share

The correct way is to copy the keys, as mentioned here. To add something to the conversation, there are times when sshpass can be convenient.

The question asks about scripts in a system with SSH. If this is an embedded system development, it may be useful to combine sshpass with command line options, as it reads in this message

 sshpass -p raspberry ssh pi@192.168.0.145 

it can be combined with

 ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no pi@192.168.0.145 

to avoid confirmation questions that prevent scripts from running.

Again, use this only in development systems where different computers use an IP address and security is not important.

https://ownyourbits.com/2017/02/22/easy-passwordless-ssh-with-sshh/

+2
source share

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

You may need to secure the rights to the authorized_keys file: chmod 600

+1
source share

Did you consider Paramiko ? This is a Python library for interacting with SSH.

+1
source share

Even if I used the pem keys for this, and this is an old topic, I also wanted to quote sshpass

+1
source share

You can use this script: https://github.com/aprey10/ssh-authorizer

It also allows you to skip the ssh key password request.

0
source share

All Articles