Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 /

share|improve this question

migrated from stackoverflow.com Oct 3 '11 at 11:15

This question came from our site for professional and enthusiast programmers.

add comment

5 Answers

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).

share|improve this answer
add comment

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.

share|improve this answer
    
lastly , what is the command ? please help me –  Jessica Watson Oct 3 '11 at 9:44
1  
@Jessica Watson, there is not "one" command, learn the tool ssh, read the documentation and tutorials on ssh, its so much more than just "enter this" "receive that", its something you mold to whatever you want once you understand how it works. –  AntonioP Oct 3 '11 at 9:45
    
cyberciti.biz/tips/… –  lollo Oct 3 '11 at 9:47
    
ummm ... i see , there is no command to connect to ssh directly . Thanks –  Jessica Watson Oct 3 '11 at 9:48
add comment

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.

share|improve this answer
add comment

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.)

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.