官方:https://www.ssh.com/ssh/

The SSH protocol uses encryption to secure the connection between a client and a server. All user authentication, commands, output, and file transfers are encrypted to protect against attacks in the network.

密钥类型包括rsa和dsa,详见 https://security.stackexchange.com/questions/5096/rsa-vs-dsa-for-ssh-authentication-keys

The security of the RSA algorithm is based on the fact that factorization of large integers is known to be "difficult", whereas DSA security is based on the discrete logarithm problem.

rsa基于大数分解,dsa基于离散对数;

RSA keys can go up to 4096 bits, where DSA has to be exactly 1024 bits (although OpenSSL allows for more.)

rsa key最高支持4096长度bit,dsa key只支持1024长度bit;

1 生成秘钥,rsa或者dsa

1.1 命令生成(linux或mac)

$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/testuser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/testuser/.ssh/id_rsa.
Your public key has been saved in /home/testuser/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:mRMuErgh17o9EPe1gzdd/tFuj6L0rVsk7qTw1rrGFCc testuser@testserver
The key's randomart image is:
+---[RSA 4096]----+
| |
| o |
|. = + o . |
| o * o + *Eo. . |
| + . + S .+o o .|
| + . o +.. + o |
| . o .o..o o o|
| . ++=oo o.|
| o*+=+o .|
+----[SHA256]-----+

创建过程会输入密码;

创建完成后默认会在home目录的.ssh目录下创建两个秘钥文件,公钥(pub后缀)和私钥

$ ls .ssh
id_rsa id_rsa.pub

登录时私钥自己保存,公钥放到服务器上

1.2 securecrt或xshell界面生成(windows)

securecrt创建秘钥的地方在

Tools--Create Public Keys

2 上传公钥

将公钥上传到要登录的服务器的用户home目录下,同时将公钥加入authorized_keys

cat .ssh/id_rsa.pub >> .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

3 本机私钥登录

3.1 ssh命令登录(linux或mac)

$ ssh -i /path/id_rsa user@remote_ip

另外还可以修改配置文件,配置key,这样就可以免掉-i

#vi /etc/ssh/ssh_config

IdentityFile ~/.ssh/id_rsa

3.2 securecrt或xshell登录(windows)

选择私钥

4 hadoop集群配置免密登录

4.1 root用户ssh免密登录

1 准备key

# ssh-keygen -t rsa -b 4096
# ls .ssh
authorized_keys id_rsa id_rsa.pub known_hosts
# cat .ssh/id_rsa.pub >> .ssh/authorized_keys
# chmod 600 .ssh/authorized_keys

2 拷贝

1)没有密码,但是可以登录到服务器,逐台登录服务器后nc接收文件

# nc -l $receive_port |tar -zxvf -

本机执行

# tar -zcvf - .ssh |nc $receive_ip $receive_port

2)有服务器的登录账号和密码,逐台拷贝

# scp .ssh/id_rsa.pub root@$server_ip:/root/.ssh
# scp .ssh/authorized_keys root@$server_ip:/root/.ssh

3 逐台ssh登录验证

# ssh $server_ip

4 逐台拷贝known_hosts

# scp .ssh/known_hosts $server_ip:/root/.ssh/

4.2 其他用户免密登陆,以hadoop为例

# ansible all-servers -m shell -a 'useradd hadoop'
# su - hadoop
$ ssh-keygen -t rsa -b 4096
$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
$ exit
# ansible other-servers -m copy -a 'src=/home/hadoop/.ssh dest=/home/hadoop/'
# ansible other-servers -m shell -a 'chown -R hadoop.hadoop /home/hadoop/.ssh && cd /home/hadoop/.ssh && chmod 600 id_rsa authorized_keys'
# su - hadoop
$ ssh $server
$ scp .ssh/known_host $server:/home/hadoop/.ssh

【原创】Linux基础之SSH秘钥登录的更多相关文章

  1. 服务器使用ssh秘钥登录并禁止密码登录

    问题: 最近在登录服务器的时候,每次都会有提示999+ falied login等字眼,意思就是自己的服务器密码正在被人暴力破解.想象以下,别人有了你的服务器的root登录密码,那么就可以对你的服务器 ...

  2. linux普通用户免秘钥登录(xshell工具环境)

    一.xshell生成密钥 1)工具->新建用户密钥生成向导 2)选择密钥类型.密钥长度(默认即可) 3)生成密钥(生成公钥和私钥) 4)为密钥加密,增加密码(可选),建议加上 5)将公钥保存为文 ...

  3. Linux SCRT本地免秘钥登录远程机器

    一.生成本地公钥和私钥 1.1.创建公钥 步骤:工具->创建公钥 然后下一步: 秘钥类型选择RSA: 然后下一步: 密钥位长度:默认是1024,我这边是2048 然后下一步: 密钥格式: 然后点 ...

  4. Xshell配置SSH秘钥登录

    秘钥生成 生成公钥 工具 -> 新建用户秘钥生成向导 -> 下一步 -> 点击下一步,输入密码: 点击下一步 点击保存为文件,完成. 生成私钥 工具 -> 用户秘钥管理者 选中 ...

  5. 通过SSH秘钥登录线上MySQL数据库(基于Navicat)

    前言 生产环境的数据库往往需要经过严格的安全限制,所以禁用密码登录,使用秘钥的方式是一种相对安全的登录方式. 原理: 角色: 主机A:其他主机,有访问线上数据库的权限 主机B:线上数据库的主机 主机C ...

  6. 腾讯云服务器,使用xshell ssh秘钥登录的时候报错:所选的用户密钥未在远程主机上注册

    1.背景 新买了台腾讯云服务器,在腾讯云控制台新建了SSH私钥,然后下载到本地. 在本地使用xshell工具,导入下载好的私钥进行登录,报错:所选的用户密钥未在远程主机上注册 2.解决方案 在确定选择 ...

  7. SSH设置秘钥登录

    设置 SSH 通过密钥登录 我们一般使用 PuTTY 等 SSH 客户端来远程管理 Linux 服务器.但是,一般的密码方式登录,容易有密码被暴力破解的问题.所以,一般我们会将 SSH 的端口设置为默 ...

  8. 在windows上使用ssh秘钥连接git服务器

    git部署在centos7上 安装好git后,新建一个用户test(注意要加入git用户组)配置ssh秘钥登录,我的另一篇博客有写配置步骤 重点的地方是在windows系统上使用秘钥登录git服务器 ...

  9. Linux SSH 免秘钥登录

    SSH 免秘钥登录 ssh:是一种安全加密协议 ssh  username@hostname     ssh gongziyuan.com:以当前用户登录该机器(如果不是当前用户,需要这么干:ssh ...

随机推荐

  1. 基于 HTML5 的 WebGL 和 VR 技术的 3D 机房数据中心可视化

    前言 在 3D 机房数据中心可视化应用中,随着视频监控联网系统的不断普及和发展, 网络摄像机更多的应用于监控系统中,尤其是高清时代的来临,更加快了网络摄像机的发展和应用. 在监控摄像机数量的不断庞大的 ...

  2. OCR技术浅析-自写篇(2)

    本例仅以本人浅薄理解,妄想自制文字识别程序,实际在识别部分未有完善. <?php class readChar{ private $imgSize; //图片尺寸 private $imgGd2 ...

  3. PS调出唯美紫蓝色天空背景女生照片

    教你学会用PS给照片叠加素材,达到想要的效果. 首先,作为摄影在拍摄前,我们要明白自己拍摄主题与目的,希望后期达到的效果,尤其是当我们需要后期叠加素材时,脑海中自然而然会有大致画面,就以“夏日”这组为 ...

  4. idea注册码到期,破解idea

    http://idea.lanyus.com/    

  5. mybatis 使用事务处理

    mybatis默认开启事务 以前使用JDBC的时候,如果要开启事务,我们需要调用conn.setAutoCommit(false)方法来关闭自动提交,之后才能进行事务操作,否则每一次对数据库的操作都会 ...

  6. tomcat 启动窗口乱码

    在tomcat主目录下的conf文件夹里,找到logging.properties文件: 用记事本打开,找到以下内容 java.util.logging.ConsoleHandler.encoding ...

  7. CodeForces 461B Appleman and T

    题目链接:http://codeforces.com/contest/461/problem/B 题目大意: 给定一课树,树上的节点有黑的也有白的,有这样一种分割树的方案,分割后每个子图只含有一个黑色 ...

  8. dubbo在idea下的使用创建 服务者,消费者 注册中心

    1.基于windows 下  spring 下的dubbo  需要书写配置文件 (1).创建带有web工程的项目 创建一个服务者 package cn.edu.aynu.bean; import lo ...

  9. 关于dubbo+zookeeper微服务的一些认识记录

    借鉴架构示意图: 实例介绍: 公司某项目架构 服务器A:nginx 服务器BC:tomcat1.tomcat2 服务器D:Dubbo+zookeeper 服务器EF:db1+zookeeper.db2 ...

  10. css高級技巧

    1.鼠標顯示 a:小手cursor:pointer b:默認cursor:default c:勾選文本cursor:text d:拖動cursor:move 2.css三種佈局模型 a.流動模型(默認 ...