How to run command with ssh on remote machine without asking for password.
My setup is 2 OpenBSD i386 machines running OpenBSD 4.1. I will call client machine redeye and server machine frodo.Our task is to run commands on server/frodo/ without enter passwords each time, so we can automate some tasks.
First setup redeye .
OpenBSD ssh
# ssh-keygen -t dsa -P ''
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
65:ab:28:e0:51:bd:2d:c9:12:57:b2:2c:ac:53:00:ff
root@noname.my.domain
#Now copy /root/.ssh/id_dsa.pub to the frodo
#scp /root/.ssh/id_dsa.pub 10.100.10.10:/tmp10.100.10.10 is IP address of frodo
Now on frodo copy id_dsa.pub to /root/.ssh/authorized_keys
#cat /tmp/id_dsa.pub >> /root/.ssh/authorized_keys#chmod 0600 /root/.ssh/authorized_keysWe are almost done.Just test.
From redeye try to execute command on frodo
#ssh 10.100.10.10 uname -a
OpenBSD koychev.com 4.1 GENERIC#1435 i386If you have any problem just enable verbose output of ssh and look where is problem or just ask here.
# ssh -v 10.100.10.10 uname -aOpenSSH_4.6, OpenSSL 0.9.7j 04 May 2006
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 10.100.10.10 [10.100.10.10] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_dsa type 2
debug1: Remote protocol version 1.99, remote software version OpenSSH_4.6
debug1: match: OpenSSH_4.6 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '10.100.10.10' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: uname -a
OpenBSD koychev.com 4.1 GENERIC#1435 i386
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
Recent comments
19 weeks 5 days ago
20 weeks 2 hours ago
25 weeks 3 days ago
25 weeks 5 days ago