I want to connect to my ssh with this command :
ssh host@myhost ls -l /
but i want to enter my password in the above command , Is this Possible ? for example our command is like this :
ssh host@myhost mypassword ls -l /
To use SSH without passwords, you'll need to set-up keys to use on your system and the target system.
[yoursystem] $ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/youruser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/youruser/.ssh/id_rsa.
Your public key has been saved in /home/youruser/.ssh/id_rsa.pub.
The key fingerprint is:
f0:7e:55:93:06:b6:c5:6f:68:67:d5:04:7f:2f:ef:df youruser@yoursystem
Then transfer the id_rsa.pub file to the target system.
On your target system then add the public key to the list of authorised keys:
cat id_rsa.pub >> ~/.ssh/authorized_keys
Log out.
If you have left the passphrase on your key empty, you can now run the command without having to be prompted for a password (your keys: private key id_rsa
on yoursystem and the public key id_rsa.pub
will be responsible for the authentication).
If you have created a passphrase for your private key (recommended), then you'd need to run the ssh-agent
to keep hold of the passphrases in memory for you:
[yoursystem] $ eval `ssh-agent`
Agent pid 1231
[yoursystem] $ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/youruser/.ssh/id_rsa:
Identity added: /home/youruser/.ssh/id_rsa (/home/youruser/.ssh/id_rsa)
Then the ssh-agent will be responsible for providing the passphrase for when you are using the private key (and importantly, the private key is protected by a passphrase and the passphrase is not stored in a file).
Try to use ssh keys to authentication. See man ssh-keygen. This is more secure way.
Use:
"-o StrictHostKeyChecking=no -o NumberOfPasswordPrompts=0 -o ConnectTimeout=30 -o ServerAliveInterval=15"
to disable interactivity.
No you cant do that, sicne that then the password would be visible by any users on your system, as the command with its arugmetns are visible by a ps aux for example.
If you need host A to ssh to host B without human intervention, then use pubkeys. Put the public key of host A onto host B and vice versa and they can then connect to each other without a password.
You can do this using expect
expect - programmed dialogue with interactive programs ( utility program ).
but you need to make script for that
#!/usr/bin/expect -f
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no USERNAME@HOSTNAME
expect "*password*"
send "$PASSWORD\r"
expect eof
You need to have expect installed on your system.
Obviously this method leaves security checks ( sometimes necessary, when there is danger of changing host identity.)
You can also use a bit of software called sshpass. It exposes your password for anyone on your system, but no keys, no expect, and relatively simple to setup. You should probably get to the point where you have keys, but that's not always possible.