How do I include a password with SSH command? (want to make shell script)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.
bash ssh
add a comment |
I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.
bash ssh
2
This still is valid: askubuntu.com/questions/46930/… :)
– Rinzwind
Dec 1 '12 at 9:38
How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get:Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
– Eva
Dec 1 '12 at 9:55
Create a new question for the TCP-port thing.
– jippie
Dec 1 '12 at 10:07
askubuntu.com/questions/224190/…
– Eva
Dec 1 '12 at 10:18
add a comment |
I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.
bash ssh
I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.
bash ssh
bash ssh
asked Dec 1 '12 at 9:35
EvaEva
3982610
3982610
2
This still is valid: askubuntu.com/questions/46930/… :)
– Rinzwind
Dec 1 '12 at 9:38
How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get:Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
– Eva
Dec 1 '12 at 9:55
Create a new question for the TCP-port thing.
– jippie
Dec 1 '12 at 10:07
askubuntu.com/questions/224190/…
– Eva
Dec 1 '12 at 10:18
add a comment |
2
This still is valid: askubuntu.com/questions/46930/… :)
– Rinzwind
Dec 1 '12 at 9:38
How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get:Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
– Eva
Dec 1 '12 at 9:55
Create a new question for the TCP-port thing.
– jippie
Dec 1 '12 at 10:07
askubuntu.com/questions/224190/…
– Eva
Dec 1 '12 at 10:18
2
2
This still is valid: askubuntu.com/questions/46930/… :)
– Rinzwind
Dec 1 '12 at 9:38
This still is valid: askubuntu.com/questions/46930/… :)
– Rinzwind
Dec 1 '12 at 9:38
How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get:
Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
– Eva
Dec 1 '12 at 9:55
How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get:
Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
– Eva
Dec 1 '12 at 9:55
Create a new question for the TCP-port thing.
– jippie
Dec 1 '12 at 10:07
Create a new question for the TCP-port thing.
– jippie
Dec 1 '12 at 10:07
askubuntu.com/questions/224190/…
– Eva
Dec 1 '12 at 10:18
askubuntu.com/questions/224190/…
– Eva
Dec 1 '12 at 10:18
add a comment |
3 Answers
3
active
oldest
votes
I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.
Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.
add a comment |
I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.
The procedure is explained here.
add a comment |
This thread on ServerFault suggests two ways, one with sshpass
:
sudo apt-get install sshpass
sshpass -p your_password ssh user@hostname
and one with expect
:
#!/usr/bin/expect -f
# ./ssh.exp password 192.168.1.11 id
set pass [lrange $argv 0 0]
set server [lrange $argv 1 1]
set name [lrange $argv 2 2]
spawn ssh $name@$server
match_max 100000
expect "*?assword:*"
send -- "$passr"
send -- "r"
interact
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f224181%2fhow-do-i-include-a-password-with-ssh-command-want-to-make-shell-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.
Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.
add a comment |
I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.
Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.
add a comment |
I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.
Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.
I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.
Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.
answered Dec 2 '12 at 6:40
Scott SeveranceScott Severance
10.5k73669
10.5k73669
add a comment |
add a comment |
I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.
The procedure is explained here.
add a comment |
I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.
The procedure is explained here.
add a comment |
I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.
The procedure is explained here.
I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.
The procedure is explained here.
answered Dec 6 '12 at 22:47
hazizhaziz
1,53752843
1,53752843
add a comment |
add a comment |
This thread on ServerFault suggests two ways, one with sshpass
:
sudo apt-get install sshpass
sshpass -p your_password ssh user@hostname
and one with expect
:
#!/usr/bin/expect -f
# ./ssh.exp password 192.168.1.11 id
set pass [lrange $argv 0 0]
set server [lrange $argv 1 1]
set name [lrange $argv 2 2]
spawn ssh $name@$server
match_max 100000
expect "*?assword:*"
send -- "$passr"
send -- "r"
interact
add a comment |
This thread on ServerFault suggests two ways, one with sshpass
:
sudo apt-get install sshpass
sshpass -p your_password ssh user@hostname
and one with expect
:
#!/usr/bin/expect -f
# ./ssh.exp password 192.168.1.11 id
set pass [lrange $argv 0 0]
set server [lrange $argv 1 1]
set name [lrange $argv 2 2]
spawn ssh $name@$server
match_max 100000
expect "*?assword:*"
send -- "$passr"
send -- "r"
interact
add a comment |
This thread on ServerFault suggests two ways, one with sshpass
:
sudo apt-get install sshpass
sshpass -p your_password ssh user@hostname
and one with expect
:
#!/usr/bin/expect -f
# ./ssh.exp password 192.168.1.11 id
set pass [lrange $argv 0 0]
set server [lrange $argv 1 1]
set name [lrange $argv 2 2]
spawn ssh $name@$server
match_max 100000
expect "*?assword:*"
send -- "$passr"
send -- "r"
interact
This thread on ServerFault suggests two ways, one with sshpass
:
sudo apt-get install sshpass
sshpass -p your_password ssh user@hostname
and one with expect
:
#!/usr/bin/expect -f
# ./ssh.exp password 192.168.1.11 id
set pass [lrange $argv 0 0]
set server [lrange $argv 1 1]
set name [lrange $argv 2 2]
spawn ssh $name@$server
match_max 100000
expect "*?assword:*"
send -- "$passr"
send -- "r"
interact
answered Mar 28 at 17:26
mmorinmmorin
1949
1949
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f224181%2fhow-do-i-include-a-password-with-ssh-command-want-to-make-shell-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
This still is valid: askubuntu.com/questions/46930/… :)
– Rinzwind
Dec 1 '12 at 9:38
How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get:
Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
– Eva
Dec 1 '12 at 9:55
Create a new question for the TCP-port thing.
– jippie
Dec 1 '12 at 10:07
askubuntu.com/questions/224190/…
– Eva
Dec 1 '12 at 10:18