I want to know how can I connect automatically using sftp with a password as an argument in the same command to get the automatic login an execute once.
Example:
I want to put it into a script, and try to make one sentence to do this task.
Cheers,
I want to know how can I connect automatically using sftp with a password as an argument in the same command to get the automatic login an execute once.
Example:
I want to put it into a script, and try to make one sentence to do this task.
Cheers,
There's four ways to do passwordless ssh/scp:
Create a new pass-phrase-free ssh key on the client, and add it to authorized_keys on the server.
As above, but set a passphrase on the key, and use ssh-agent to unlock it in advance of running scp.
Use ssh connection sharing, perhaps with an appropriate ControlPersist setting, to log into the server in advance of your scp running. The scp will reuse the same connection and not need a password.
Use some dodgy script to enter the password, but ssh/scp actively discourage this so it's not as easy as you'd like.
I strongly suggest you investigate the first two options (option 2 being more secure), and option 3 if authorized_keys are not available. There are plenty of places documenting how to do it.
Option 4 is possible (I see someone else has already posted a solution), but you need to be aware that that will leak your password to other users of the machine and/or anybody who can read your script. The ssh keys are protected from all but the root user, and pass-phrase protected keys are protected even from root (ssh-agent hacks aside).
Run the following:
ssh-keygen -t rsa -b 2048
then
touch ~/.ssh/config
Now edit config to look something like:
# host-specific options
Host enigma
HostName mydomain.com
Port 2547
ServerAliveInterval 120
User YOURUSERNAME
TCPKeepAlive Yes
Now connect
ssh-copy-id [email protected]
You should be able to connect to the Server using the Hostname in the config file.
i.e. ssh enigma
I have about 20 connections in my Config file, and all short referenced so i dont have to type the domain and password each time.
The secuirty flaw to this, is that all SSH connections unless you start creating different Hostfiles. Are in one file. Protected by one password. So if you store 20 Connections to the one file, Then if that one password is compromised then so are all 20 connections.
I use a couple of hosts file, Personal, Work and Misc its not too much of a issue if a password is leaked then