How to enter ssh password using bash? [duplicate]
This question already has an answer here:
- Bash: controlling SSH 8 answers
Everyday I am connecting to a server through ssh. I go through this routine:
IC001:Desktop user$ ssh user@my.server.com
user@my.server.com's password:
Last login: Tue Jun 4 10:09:01 2013 from 0.0.0.0
$
I would like to automate this process and create a bash script to do it for me. I don't care about security and okay to store my password openly in the script. I am also okay for it to get typed openly on the screen while the script gets executed. So I've created this:
#!/bin/bash
ssh user@my.server.com
echo mypassword
But it doesn't work. I've also tried send instead of echo, but it also didn't work. Please advise if it is possible to do.
Double check if you are not able to use keys.
Otherwise use expect:
#!/usr/bin/expect -f
spawn ssh user@my.server.com
expect "assword:"
send "mypassword\r"
interact
Create a new keypair: (go with the defaults)
ssh-keygen
Copy the public key to the server: (password for the last time)
ssh-copy-id user@my.server.com
From now on the server should recognize your key and not ask you for the password anymore:
ssh user@my.server.com
참고URL : https://stackoverflow.com/questions/16928004/how-to-enter-ssh-password-using-bash
'Nice programing' 카테고리의 다른 글
| Visitor pattern's purpose with examples [duplicate] (0) | 2020.09.25 |
|---|---|
| how to delete the content of text file without deleting itself (0) | 2020.09.25 |
| Renaming part of a filename [duplicate] (0) | 2020.09.25 |
| How to display loading image while actual image is downloading [duplicate] (0) | 2020.09.25 |
| Text size of android design TabLayout tabs (0) | 2020.09.25 |