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/

时间: 2024-08-18 04:33:02

SSH login without password的相关文章

通过EMClient.getInstance().login(username, password, new EMCallBack() {};登录时,有时登录成功,有时登录失败

问题描述 经常登录失败,是什么导致的? 解决方案 看看失败的提示

技术备忘3

   shell单引号与变量 [root@test] a=55 [root@test] echo $a 55 [root@test] echo '$a' $a [root@test] echo ''$a'' #注意此处是两个单引不是一个双引 55 总结: 在单引号中引用变量,需要这样来写(单引号括起来双引号内的变量.) :   '"${a}"' 原文地址 date星期求取 <span style="font-family:Microsoft YaHei">

AR系列路由器使用SSH用户验证方式为password登录路由器的典型配置_路由器、交换机

 大 | 中 | 小    SSH是Secure Shell(安全外壳)的简称,用户通过一个不能保证安全的网络环境远程登录到路由器时,SSH特性可以提供安全保障和强大的认证功能,以保护路由器不受诸如IP地址欺诈.明文密码截取等等的攻击. 使用SSH Client通过password方式登录路由器 # sysname Quidway # radius scheme system # domain system # local-user huawei             /创建本地帐号"huaw

ssh框架登录报404求大神解答!!!

问题描述 ssh框架登录报404求大神解答!!! 我的源码: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > context

CISCO的HTTP/HTTPS/SSH配置测试完成

按实验一步一步,倒是很容易的,也理解罗~~ START-CONFIG粗配置文件如下: r1#show run Building configuration... Current configuration : 2488 bytes ! version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname r

Linux 利用hosts.deny 防止暴力破解ssh(转)

一.ssh暴力破解 利用专业的破解程序,配合密码字典.登陆用户名,尝试登陆服务器,来进行破解密码,此方法,虽慢,但却很有效果. 二.暴力破解演示 2.1.基础环境:2台linux主机(centos 7系统).Development Tools. 主机ip:192.168.30.64 (服务器端).192.168.30.64(客户端+ 暴力破解[Hydra]) 在30.63上进行暴力破解30.64 2.2 客户端上安装 破解程序 hydra.关于该程序的详情请去官网. 安装该软件的依赖环境: [r

43.2. /etc/ssh/

43.2.1. sshd_config # vi /etc/ssh/sshd_config 43.2.1.1. Authentication 配置 连接后2m没有任何键盘输入以及屏幕输出,将自动切换SSH连接. LoginGraceTime 2m 禁止root用户登录(disable root SSH login) PermitRootLogin no 限制SSH验证重试次数(maximum number of authentication): MaxAuthTries 6 43.2.1.2. 

command line explicit password record security

在命令行中使用密码的话, 有几个坏处,  1. 因为命令会记录到命令历史中, 所以使用history就能看到命令行中的密码. 2. 如果使用了远程syslog或其他类似的操作日志收集工具的话, 这些包含了密码的命令最终还会记录到远程, 所以泄密的风险范围再次扩大. 3. ~/.psql_history 4. pg_stat_statements插件中也会记录SQL, postgres=# \d pg_stat_statements View "public.pg_stat_statements&

SSH::Batch,在公有云中使用 ssh 工具箱

就像之前的博文中讲的那样,我买了两台阿里云的 ECS,一台在香港,一台在新加坡.由于总所周知的网络原因,从大陆 ping 这两台服务器的 RTT 一直都在两三百毫秒,之前只有一台位于香港的 ECS 的时候,我 ssh 上去部署一些服务,碰上网络抖动的时候都能卡出翔,敲击一个按键之后许久才出现在屏幕上.(之前写这篇博文的时候网络状况确实如此,现在网络状况已经好了很多很多,亲测杭州 ping 香港和新加坡的 ECS RTT 在 100ms 以内) 如今我有了两台服务器,如果还像之前那样直接用 ssh