This question already has answers here:
Shell script to automate SSH login using password
(2 answers)
Closed 5 years ago.
I'm trying to see if its possible to insert my password to below command.
sftp -o “Port 44444” myusername#mysite.com
Im looking to have a one line command to login into our sftp.
Thanks
No. It is not secure and therefore not possible with native OpenSSH tools. But you can use sshpass:
sshpass -p password sftp -o “Port 44444” myusername#mysite.com
or rather set up pubkey authentication:
ssh-keygen -t rsa -f ~/.ssh/id_rsa
ssh-copy-id -o “Port 44444” myusername#mysite.com
Related
This question already has answers here:
Shell script to automate SSH login using password
(2 answers)
Closed 5 years ago.
I am trying to make a script in bash that connects via ssh to another machine.
I only have user access to this machines so
I can't use expect (It is not installed and I can't install it)
I can't install ssh keys
So I have to log in via username and password.
Is there a way to make my script send my password just using bash?
You can do that with sshpass, however, it's insecure.
sshpass -p YOUR_PW ssh ...
That will connect without asking for password.
You might need to add the flag -oStrictHostKeyChecking=no to ssh for auto-accepting keys.
This question already has answers here:
How to enter ssh password using bash? [duplicate]
(2 answers)
Closed 7 years ago.
I have a simple bash application in Mac OS that establishes a SSH connection.
the code is like this:
$ ssh user1#machine.com -p61023
When I run the script, console always prompts asking for a password. (It is a very rudimentary process)
appelelog#sunlineclass.com's password:
How I can automate this process?
Create a key pair.
Add the private key to the Keychain: ssh-add -K ~/.ssh/host_id_rsa.
Never type the password again, other than the login password.
If you run the server, then other things I do:
Listen on port 422 instead of 22, to reduce break-in attempts.
Only allow login via public/private key pairs, and not passwords.
Only allow login by a select list of users (never root).
This question is off-topic, however, and you should have asked it here.
#Kalanidhi gave me a hint:
Here is my new script
sshpass -p 'yourpassword' ssh user#machine.com -p61023
This question already has answers here:
How to run the sftp command with a password from Bash script?
(12 answers)
Closed 8 years ago.
Is it possible to pass SFTP USER/PASS to a server in an automated script that will log in and retrieve a file?
I know that KEY PAIRS are the recommended method but assume thats not possible in this case.
In the simplest case you use a key based authorization so you don't need to enter any credentials.
For doing that create a key:
ssh-keygen -t rsa
And copy it to the target system:
ssh-copy-id -i ~/.ssh/id_rsa.pub user#remote-system
Now you can login to the system without a password.
If your problem is the missing ssh-copy-id command try this here:
cat ~/.ssh/*.pub | ssh user#remote-system 'umask 077; cat >>.ssh/authorized_keys'
This question already has answers here:
How to run the sftp command with a password from Bash script?
(12 answers)
Closed 8 years ago.
I need to make a shell script that will transfer files to a remote server however, the account given to me has no shell mainly because they want to restrict the access to sftp only. I already have a shell script my only problem is that I cannot automate it. The script stops on the password prompt. I read on most of the passwordless sftp tutorials that I need to generate a keypair but like i've said I cannot do this as the remote account has no shell access. What are the alternatives for passwordless sftp considering an account without shell? The remote server has no 'expect' installed.
Thank you very much.
EDIT: Please also note that I cannot install anything in the local server. I MAY be able to do something on the remote server but not on the local.
On Debian and Ubuntu (maybe other systems also) you can use sshpass
apt-get install sshpass
sshpass -p 'YourPassword' ssh user#host
OR
sshpass -p 'YourPassword' sftp user#host
But the you will have your password printed in your bash_history..
So you might want to pass the password from a file or an environment-variable.
Greets, Eric
This question already has answers here:
Bash: controlling SSH
(8 answers)
Closed 9 years ago.
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