Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: controlling SSH

Tags:

bash

ssh

controls

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 several linux distro's, and also on Mac?

like image 939
Deniz Zoeteman Avatar asked Dec 17 '09 20:12

Deniz Zoeteman


People also ask

Can a bash script SSH?

Bash script SSH is a common tool for Linux users. It is needed when you want to run a command from a local server or a Linux workstation. SSH is also used to access local Bash scripts from a local or remote server.


1 Answers

The proper way to do this without storing passwords in plaintext on your machine is with ssh. First run:

ssh-keygen

This will generate a new SSH key in ~/.ssh/id_rsa.pub. After that simply run:

ssh-copy-id [email protected]

If you're on OS X or another machine that does not have "ssh-copy-id" there are one-line alternatives such as this one:

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

Ultimately you just need to append the contents of ~/.ssh/id_rsa.pub on your local machine to ~/.ssh/authorized_keys on the remote server. How you do that is up to you, the above are just quick shortcuts to do that.

like image 152
Chev Avatar answered Sep 18 '22 22:09

Chev