android openssl 添加 openssl dh_用户名

OpenSSH

OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现。SSH协议族可以用来进行远程控制, 或在计算机之间传送文件。而实现此功能的传统方式,如telnet(终端仿真协议)、 rcp ftp、 rlogin、rsh都是极为不安全的,并且会使用明文传送密码。OpenSSH提供了服务端后台程序和客户端工具,用来加密远程控制和文件传输过程中的数据,并由此来代替原来的类似服务。

OpenSSH是使用SSH透过计算机网络加密通讯的实现。它是取代由SSH Communications Security所提供的商用版本的开放源代码方案。目前OpenSSH是OpenBSD的子计划。

OpenSSH常常被误认以为与OpenSSL有关联,但实际上这两个计划的有不同的目的,不同的发展团队,名称相近只是因为两者有同样的软件发展目标──提供开放源代码的加密通讯软件。

OpenSSH服务,sshd,是一个典型的独立守护进程(standalone daemon),但也可以根据需要通过网络守护进程。

android openssl 添加 openssl dh_重启_02


  • 安装 openssh

android openssl 添加 openssl dh_重启_03

  • 使用 ssh 用户名+密码 方式登录
  • openssh的主配置文件为 /etc/ssh/ 目录下的 ssh_config 和 sshd_config
  • ssh_config和sshd_config都是ssh服务器的配置文件,二者区别在于,前者是针对客户端的配置文件,后者则是针对服务端的配置文件

android openssl 添加 openssl dh_配置文件_04

  • 这里只配置 sshd_config 
  • vim /etc/ssh/sshd_config        #需要root权限
  • 修改以下几项

android openssl 添加 openssl dh_用户名_05

  • Port 22                                   #sshd服务运行端口,默认为22                         
    SyslogFacility AUTHPRIV       #定义ssh的日志记录在 /var/log/secure 文件中
    PermitRootLogin yes              #允许 root 用户网络登录
    PermitEmptyPasswords no     #是否允许空密码登录,设置为no 不允许
    PasswordAuthentication yes   #是否允许使用密码登录,设置为允许
    UsePAM no                            #是否使用PAM验证
    UseDNS no                            #是否允许DNS查询,选择 no 关闭
    AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
    AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
    AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
    AcceptEnv XMODIFIERS
    Subsystem    sftp    /usr/libexec/openssh/sftp-server
  • 确认无误后保存退出,重启ssh服务

android openssl 添加 openssl dh_重启_06

  • 在另外一台机器上登录
  • ssh 用户名@IP      登录的用户要事先存在于要登录的机器上,并设置有密码。
  • 按提示输入密码

android openssl 添加 openssl dh_重启_07


  • 在生产环境中,如果让root用户直接可以使用网络登录是非常危险的,所以下面制定更高安全级别的登陆方式:密钥登录
  • 使用 ssh-keygen 命令来生成密钥对
  • 使用需要登录的用户生成密钥对

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_08

  • Generating public/private rsa key pair.
    Enter file in which to save the key (/home/test/.ssh/id_rsa): #默认存放密钥的目录及密钥名称 id_rsa (默认基于rsa算法)
    Enter passphrase (empty for no passphrase):                      #是否给密钥设置密码
    Enter same passphrase again: 
    Your identification has been saved in /home/test/.ssh/id_rsa.    #生成密钥对的存放目录及名称
    Your public key has been saved in /home/test/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:q12boL6CTiU1DSBRt6/rPpwoIi/8mVI1Aq5POWbUUIU test@server10.2
    The key's randomart image is:                                                #rsa 2048 为密钥的长度
    +---[RSA 2048]----+
    |oooo+o.          |
    | o..E+           |
    |. .o+ .          |
    | ..o.=           |
    |....+ o S        |
    |. *+ .   .       |
    |.=o=..  o .      |
    |=++ B. + o o     |
    |o==*++=.. o      |
    +----[SHA256]-----+
  • 私密钥文件 id_rsa 一定要保存好,不能泄漏
  • 将公密钥文件 id_rsa.pub 的内容写入本地 authorized_keys 私钥验证文件中

android openssl 添加 openssl dh_用户名_09

  • 在使用密码验证方式登录的情况下,可以使用 ssh-copy-id 将公钥复制到远程机器
  • ssh-copy-id -i .ssh/id_rsa.pub  用户名@对方IP
  • 注意: ssh-copy-id 将key写到远程机器的 ~/ .ssh/authorized_key.文件中

注意 .ssh 目录和 authorized_keys 文件的权限

.ssh 目录权限必须为 700  authorized_keys 文件权限必须为 644

  • chmod 700 ~/.ssh
  • chmod 644 ~/.ssh/authorized_keys

android openssl 添加 openssl dh_配置文件_10


  • Permission denied (publickey,keyboard-interactive).权限被拒绝(公钥、键盘交互)  一般这个报错就是文件权限引起的

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_11


  • 编辑 /etc/ssh/sshd_config

android openssl 添加 openssl dh_重启_12

  • Port 22
    SyslogFacility AUTHPRIV
    PermitRootLogin no                                        #禁止root用户网络登录
    PubkeyAuthentication yes                              #开启密钥认证
    AuthorizedKeysFile    .ssh/authorized_keys    #指明密钥认证文件存放位置及名称,这里使用的是相对路径
    PermitEmptyPasswords no                             #不允许空密码登录
    PasswordAuthentication no                            #不允许密码方式登录
    UsePAM no
    UseDNS no
     
  • 重启服务之前,建议多开一个 ssh 链接,万一配置有问题方便处理
  • 确认无误保存退出,重启sshd服务
  • systemctl restart sshd
  • 登录测试
  • 切换为生成 ssh-keygen 的用户
  • ssh test@192.168.10.2

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_13


  • 将公密钥 id_rsa.pub 文件中的 key 复制到其他机器上的 authorized_keys 密钥验证文件中

注意 :id_rsz.pub 文件中的 Key 为一行,没有换行

单方通信只需要对方机器的 id_rsz.pub 文件中的 Key

  • A 机器上的 authorized_keys 密钥认证文件中有 B 机器密钥key的信息,所以在 B 机器上可以登陆 A 机器
  • 反之在 B 机器上的 authorized_keys 密钥认证文件中没有 A 机器的key,所以在 A 机器上无法登陆 B 机器

android openssl 添加 openssl dh_重启_14

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_15

双方通信 authorized_keys 文件中要有双方机器 id_rsz.pub 文件中的 Key

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_16

  • 在另外一台机器上测试

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_17

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_18


  • 配置好使用密钥认证登录后,在 WINDOWS 上使用 Xshell 密钥认证方式登录 Linux
  • 打开 Xshell 点击 工具--新建用户密钥生成向导

android openssl 添加 openssl dh_配置文件_19

  • 默认密钥类型 rsa ,密钥长度 2048位

android openssl 添加 openssl dh_配置文件_20

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_21

android openssl 添加 openssl dh_用户名_22

android openssl 添加 openssl dh_用户名_23

android openssl 添加 openssl dh_android openssl 添加_24

android openssl 添加 openssl dh_重启_25

android openssl 添加 openssl dh_Linux OpenSSH 密钥登录_26

android openssl 添加 openssl dh_重启_27

  • rz 命令属于 lrzsz 包
  • 在 Linux 机器上使用哪个用户登陆,就在对应用户家目录下的 authorized_keys 文件中添加密钥认证 key

android openssl 添加 openssl dh_用户名_28

android openssl 添加 openssl dh_android openssl 添加_29

  • 在 Linux 机器上使用哪个用户登陆就在对应用户家目录下的 authorized_keys 文件中添加密钥认证 key
  • 填写对应的用户名
  • 填写用户 key 文件的加密密码

android openssl 添加 openssl dh_android openssl 添加_30

android openssl 添加 openssl dh_配置文件_31

android openssl 添加 openssl dh_用户名_32