由于项目的需求,我这边ubuntu下常常需要SSH访问另外一台MACOS。
每次输入密码有点烦,就想到RSA公钥和密钥验证的方法。
像所有教程上讲的一样,本机执行
gong@hzsx:~$ ssh-keygen -t rsa
将公钥拷贝到MACOS的/tmp下,并给其他人以读权限:
gong@hzsx:~$ scp .ssh/id_rsa.pub git@192.168.1.123:/tmp 
git@192.168.1.123's password: 
id_rsa.pub                                    100%  390     0.4KB/s   00:00
于是登陆了MACOS,这里需要做一些准备工作。
MACOS用户目录下没有.ssh目录。更不用说.ssh下authorized_keys文件了。
dev-mini:~ devone$ mkdir .ssh
dev-mini:~ devone$ sudo chmod 740 /tmp/id_rsa.pub
dev-mini:~ devone$ sudo cat /tmp/id_rsa.pub >> /home/devone/.ssh/authorized_keys
dev-mini:~ devone$ sudo chmod 740 /home/devone/.ssh/authorized_keys
dev-mini:~ devone$ exit
为了以后ssh访问方便 我在本机添加一个配置文件
gong@hzsx:~$ cd .ssh/
gong@hzsx:~/.ssh$ vim config
添加以下内容
Host dev-mini
HostName dev-mini.local
User devone
IdentityFile ~/.ssh/id_rsa
以后ssh访问MAC OS,我就可以直接
gong@hzsx:~/.ssh$ ssh dev-mini
但是还是让输入密码。
我想应该是MAC OS上sshd_config的配置问题。不是ssh_config哦。
输密码进去
dev-mini:~ devone$ sudo vim /etc/sshd_config
修改后如下:
#    $OpenBSD: sshd_config,v 1.89 // :: dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config() for more information. # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin # The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value. # See sshd_config() for details on setting the Port and Listen values on Mac OS X
Port 
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress :: # The default requires explicit activation of protocol 
Protocol  # HostKey for protocol version 
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 
HostKey /etc/ssh_host_rsa_key
HostKey /etc/ssh_host_dsa_key
HostKey /etc/ssh_host_ecdsa_key # Lifetime and size of ephemeral version  server key
KeyRegenerationInterval 1h
ServerKeyBits  # Logging
# obsoletes QuietMode and FascistLogging
SyslogFacility AUTHPRIV
LogLevel INFO # Authentication: LoginGraceTime 2m
PermitRootLogin yes
StrictModes no
#MaxAuthTries 
#MaxSessions  RSAAuthentication yes
PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile    .ssh/authorized_keys #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 
HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes # To disable tunneled clear text passwords both PasswordAuthentication and
# ChallengeResponseAuthentication must be set to "no".
PasswordAuthentication yes
PermitEmptyPasswords no # Change to no to disable s/key passwords
ChallengeResponseAuthentication no # Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes # GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no # Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
# Also, PAM will deny null passwords by default.  If you need to allow
# null passwords, add the "    nullok" option to the end of the
# securityserver.so line in /etc/pam.d/sshd.
UsePAM yes #AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#XauthLocation xauth # Default is to search $PATH (set by launchd()).  It is recommended that a full path be provided.
X11DisplayOffset 
#X11UseLocalhost yes
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation yes        # Default for new installations.
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 
#ClientAliveCountMax 
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups ::
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none # pass locale information
AcceptEnv LANG LC_* # no default banner path
#Banner none # override default of no subsystems
Subsystem    sftp    /usr/libexec/sftp-server # Example of overriding settings on a per-user basis
#Match User anoncvs
#    X11Forwarding no
#    AllowTcpForwarding no
#    ForceCommand cvs server
尤其注意这几个路径
HostKey /etc/ssh_host_rsa_key
HostKey /etc/ssh_host_dsa_key
HostKey /etc/ssh_host_ecdsa_key
中间不是 /etc/ssh/ssh_host_rsa_key
dev-mini:~ devone$ exit
gong@hzsx:~$ ssh dev-mini
dev-mini:~ devone$
终于搞定了。

linux下ssh使用rsa验证登陆MACOX的更多相关文章

  1. linux下ssh/scp无密钥登陆方法

    一.双方机器都是root用户登陆方法 A为本地主机(即用于控制其他主机的机器) ;B为远程主机(即被控制的机器Server), 假如ip为192.168.60.110;A和B的系统都是Linux 在A ...

  2. linux下ssh key秘钥登陆远程服务器设置

    本地的用户名需要和ssh服务器的用户名一致 1.在Server服务器上加载私钥文件ssh-add wang_rsa 2.如果系统提示:could not open a connection to yo ...

  3. Linux下SSH免密码登录

    转自:http://haitao.iteye.com/blog/1744272 ssh配置 主机A:10.0.5.199 主机B:10.0.5.198 需要配置主机A无密码登录主机A,主机B 先确保所 ...

  4. Linux下SSH+Firefox

    Linux下SSH+Firefox 简明FQ攻略 FQ的软件有很多,楼主原来在Windows下用过Tor(洋葱头).Puff.freegate等,一般只需要打开FQ软件,简单的设置后就可以FQ浏览了. ...

  5. linux下ssh端口的修改和登录

    linux下ssh端口的修改和登录 首先修改配置文件 vi /etc/ssh/sshd_config 找到#Port 22一段,这里是标识默认使用22端口,添加如下一行: Port 50000 然后保 ...

  6. Linux 下 SSH 远程超时解决方案

    Linux 下 SSH 远程超时解决方案 今天突然看到一个问题说是如何解决SSH远程超时的问题. 找了一点资料.用于解决这个需求~ 第一种:OpenSSH 配置文件设置 位于112行的 "C ...

  7. 解决Linux下SSH超时自动断开

    title: 解决Linux下SSH超时自动断开 comments: false date: 2019-08-19 19:22:55 description: Linux 下 SSH 超时自动断开?? ...

  8. hadoop搭建杂记:Linux下ssh免密码登陆

    关于ssh免密码登陆的问题 关于ssh免密码登陆的问题 linux下可以用ssh-keygen来生成公钥/私钥对 ①生成id_rsa和id_rsa.pub公钥/私钥对,自动在~/.ssh下生成文件(亦 ...

  9. Linux下 SSH远程管理服务

    第1章 SSH基本概述 1.1 SSH服务协议说明 SSH 是 Secure Shell Protocol 的简写,由 IETF 网络工作小组(Network Working Group )制定 在进 ...

随机推荐

  1. EOJ-1708//POJ3334

    题意: 有一个连通器,由两个漏斗组成(关于漏斗的描述见描述). 现向漏斗中注入一定量的水,问最终水的绝对位置(即y轴坐标) 思路: 总体来说分为3种情况. 1.两个漏斗可能同时装有水. 2.只可能a漏 ...

  2. 强强合体:Docker版Kali Linux发布

    Kali Linux是一款开源的基于Debian的渗透测试专用操作系统,系统中包含一系列用于渗透测试的神器.最近,Kali的开发者们为喜爱Docker的童鞋们发布了新版本. FreeBuf百科:什么是 ...

  3. Linux下的动态连接库及其实现机制

    Linux与Windows的动态连接库概念相似,但是实现机制不同.它引入了GOT表和PLT表的概念,综合使用了多种重定位项,实现了"浮动代码",达到了更好的共享性能.本文对这些技术 ...

  4. [译]再次对比TCP与UDP

    免责声明:和往常一样,此文章的观点都属于‘No Bugs’Hare(译注:一个网站) ,也许不一定和翻译者或者Overload编辑的意见一致.同时,翻译者从Lapine翻译到英语也具有一定的难度.除此 ...

  5. android 电容屏(三):驱动调试之驱动程序分析篇

    平台信息: 内核:linux3.4.39系统:android4.4 平台:S5P4418(cortex a9) 作者:瘋耔(欢迎转载,请注明作者) 欢迎指正错误,共同学习.共同进步!! 关注博主新浪博 ...

  6. Windows下Vim设置

    进入安装目录,找到_vimrc文件,用文本编辑器打开,在前面加入下述内容 设置中文支持 " 设置编码自动识别, 中文引号显示 " set fileencodings=utf-8,c ...

  7. extends:类似于java中的继承特征,extends="struts-default"

    extends:类似于java中的继承特征,extends="struts-default"就是继承struts-default.xml,它里面定义了许多跳转类型.拦截器等一些常用 ...

  8. 函数buf_LRU_free_from_unzip_LRU_list

    /******************************************************************//** Try to free an uncompressed ...

  9. Unity3d插件推荐

    2D_Toolkit_1.51 动画开发插件包 FingerGestures 触摸插件 ORK_Okashi_RPG_Kit Unity3D角色扮演游戏开发工具包 uScript-Visual-Scr ...

  10. entity framework 查询

    1.简单查询: SQL: SELECT * FROM [Clients] WHERE Type=1 AND Deleted=0 ORDER BY ID EF: //Func形式 var clients ...