SSH login without password

简介:
Your aim

 

You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.

How to do it

First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:

1
2
3
4
5
6
7
8
9
10
a @A :~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory  '/home/a/.ssh' .
Enter passphrase (empty  for  no  passphrase):
Enter same passphrase again:
Your identification  has  been saved in /home/a/.ssh/id_rsa.
Your public key  has  been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a @A

  Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

1
2
a @A :~> ssh b @B  mkdir  -p .ssh
b @B 's password:

  Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

1
2
a @A :~> cat .ssh/id_rsa.pub | ssh b @B  'cat >> .ssh/authorized_keys'
b @B 's password:

  From now on you can log into B as b from A as a without password:

1
2
a @A :~> ssh b @B  hostname
B

  

A note from one of our readers: Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640

参考文章:SSH Passwordless Login Using SSH Keygen in 5 Easy Steps

http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/


==============================================================================
本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/articles/3565823.html,如需转载请自行联系原作者

相关文章
|
5月前
|
Linux 网络安全 数据安全/隐私保护
Jun 03 14:50:45 nodeName sshd[60215]: Accepted password for root from 192.168.0.100 port 15612 ssh2 如何关闭这个连接
【6月更文挑战第6天】Jun 03 14:50:45 nodeName sshd[60215]: Accepted password for root from 192.168.0.100 port 15612 ssh2 如何关闭这个连接
84 2
|
6月前
|
监控 安全 网络安全
Failed password for invalid user www from xx.xx.xx.xxx port xxxxx ssh2 问题处理
【5月更文挑战第6天】Failed password for invalid user www from xx.xx.xx.xxx port xxxxx ssh2 问题处理
621 1
|
jenkins Java 网络安全
ssh Permission denied (publickey,password).
        项目启动报错: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoService': FactoryBean threw .
10029 2
|
网络安全 Shell Linux
|
5月前
|
安全 Linux Shell
Linux中SSH命令介绍
Linux中SSH命令介绍
116 2
|
3月前
|
安全 Linux 网络安全
在Linux中,如何配置SSH以确保远程连接的安全?
在Linux中,如何配置SSH以确保远程连接的安全?
|
3月前
|
安全 Linux Shell
SSH 命令完整实用指南 | Linux SSH 服务
【8月更文挑战第20天】
348 0