由于项目的需求,我这边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. firefly服务器间通信演示

    源地址:http://www.9miao.com/question-15-54560.html 最近好多童鞋都在问firefly几个服务器之间是如何通信的,其实在之前的distributed使用文档中 ...

  2. hdu 4672 Present Day, Present Time 博弈论

    看了解题报告才知道怎么做!! 题意:有 N 堆石子和 M 个石子回收站,每回合操作的人可以选择一堆石子,从中拿出一些 放到石子回收站里(可以放进多个回收站,每个回收站可以使用无数次),但每个石子回收站 ...

  3. 到底该不该熟悉掌握struts2的ONGL呢?

    其实,在学习网站开发过程中,其实不掌握ONGL也是可以的.我们完全可以使用JSTL和EL来代替OGNL. 只要存在要往页面传输内容,我们直接把对象放在request范围即可,这样我们就可以在jsp中使 ...

  4. codeforces #310 div1 A

    首先我们考虑最暴力的拆解拼凑 显然拆分掉所有的链需要 n-m 次 之后拼凑需要 n-1 次 然后由题目规定可知:只有从1出发且连续的链不用拆掉,其余的都必须拆掉(因为两个都套有娃娃的套娃不能组合) 我 ...

  5. 解读Q_GLOBAL_STATIC(QFontDatabasePrivate, privateDb)

    根据 src/corelib/global.h template <typename T>class QGlobalStatic{public: T *pointer; inline QG ...

  6. QListWidget代码刷新界面

    我有一个特殊效果要求实现(其实很弱智,也变成特殊效果,汗一下自己):两个QRadioButton切换的时候,让旁边的QListWidget自动变化不同的背景色.想了很多办法: 1. 控件自己刷新,不行 ...

  7. *JRebel 热部署

    Jrebel是一套商业Java开发软件,可快速实现热部署,节省大量重启时间,提高开发效率. 去IDEA的插件官网下载插件:http://plugins.jetbrains.com/plugin/444 ...

  8. dp和px,那些不得不吐槽的故事——Android平台图

    http://blog.sina.com.cn/s/blog_6499f8f101014ipq.html 一个优秀的手机软件,不仅要有精巧的功能,流畅的速度,让人赏心悦目的UI也往往是用户选择的重要理 ...

  9. WPF中映射clr namspace

    1. xaml中直接映射为prefix xmlns:prefix="clr-namespace:MyApplication.Modules.Entity;assembly=MyAssembl ...

  10. html5自带表单验证-美化改造

    神奇的代码 暂且叫做html5.css /* === HTML5 validation styles === */ .myform select:required, .myform input:req ...