How to: Password-less ssh#

Writing your little expect script.#

If the above still doesn’t work, below is a workaround 1.

  • Create a file called osc using any editor you like.

  • Put the following content inside osc.

    #!/usr/bin/expect -f
    
    spawn ssh YOUR_USERNAME@pitzer.osc.edu
    
    expect "assword:"
    send "YOUR_PASSWORD\r"
    interact
    
  • Replace YOUR_USERNAME with your OSC username and YOUR_PASSWORD with your OSC password.

    Warning

    Do make sure to keep the \r (after YOUR_PASSWORD). Alternatively, it could be a \n (newline character).

  • At this point, you want to make sure you are the only person that is authorized to execute this script. Exit the text editor and in the terminal, change access to file using

    chmod 700 osc
    
  • You can set an alias in your .bashrc (or .zshrc) to execute this script, or you could place it in a directory where your computer automatically looks. For instance, on my mac, the path of this file is at

    /usr/local/bin/osc
    
  • And now whenever I type osc, I ssh into OSC without having to type my password!


1(1,2)

Copied from stackoverflow