SSH without password

  • We using ssh-copy-id to installing an SSH key on a server as an authorized key
  • Its purpose is to provision access without requiring a password for each login
  • Read offical document here

Managing multiple remote host

  • When you have to manage a bunch of servers, it will be difficult to remember all the IP addresses or passwords
  • We will create a bunch of bash files corresponding to the servers we manage
  • Every time access a certain remote host, we just need to execute a bash file with an easier to remember filename
  • At first, we create an expect file run.exp:
#!/usr/bin/expect -f
set host [lindex $argv 0]
set password [lindex $argv 1]

spawn ssh $host
expect "assword"
send "$password\r"
interact
  • We create a bash file test.sh, replace our host and password variable:
#/bin/sh
host='root@12.34.56.78'
password='%_$5.3T^NF>M$hG"'

/path/to/run.exp $host $password
  • Execute to access remote host:
    $ /path/to/test.sh