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,如需转载请自行联系原作者

相关文章
|
jenkins Java 网络安全
ssh Permission denied (publickey,password).
        项目启动报错: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoService': FactoryBean threw .
9876 0
|
3月前
|
Linux 网络安全
Linux命令(124)之ssh
Linux命令(124)之ssh
33 2
|
1月前
|
安全 Shell Linux
【Shell 命令集合 文件管理】Linux ssh 远程主机之间复制文件 scp 命令使用教程
【Shell 命令集合 文件管理】Linux ssh 远程主机之间复制文件 scp 命令使用教程
36 0
|
5月前
|
监控 数据可视化 安全
Linux——怎样使用SSH服务实现远程UI界面本地显示
需求场景 最近几天需要实现软件的远程监控,但是实际场景又不能使用向日葵、VNC、AnyDesk、以及其他的监视软件,并且软件的整体设计也没有这块的数据上行设计。
195 0
|
6天前
|
网络协议 安全 Linux
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
|
4月前
|
安全 网络协议 Linux
Linux ssh 命令详解
Linux ssh 命令详解
121 0
|
1月前
|
网络协议 Ubuntu Linux
「远程开发」VSCode使用SSH远程linux服务器 - 公网远程连接
「远程开发」VSCode使用SSH远程linux服务器 - 公网远程连接
129 0