转自:http://blog.csdn.net/zzk197/article/details/7915307

一:简洁的配置文件
[root@cisco ~]# vi /etc/ssh/sshd_config

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 600
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
RhostsAuthentication no
IgnoreRhosts yes
HostbasedAuthentication no
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
MaxStartups 20
Subsystem       sftp /usr/libexec/openssh/sftp-server
~

二、使用公钥认证
1、原理:首先由用户生成一对密钥,然后将公钥保存在SSH服务器用户的目录下.ssh子目录中的authorized_key文件里(/root/.ssh/authorized_key).私钥保存在本地计算机.当用户登陆时,服务器检查authorized_key文件的公钥是否与用户的私钥对应,如果相符则允许登入,否则拒绝.由于私钥只有保存在用户的本地计算机中,因此入侵者就算得到用户口令,也不能登陆到服务器.
2、启用公钥认证
修改配置文件/etc/ssh/sshd_config 
将"PasswordAuthentication yes"修改为"PasswordAuthentication no"
3、生成密钥
[root@rain ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
4d:dd:48:af:76:c2:ba:a8:bc:20:f3:28:1d:6a:28:53 root@rain.fish.com
4、将/root/.ssh/id_rsa.pub改名为/root/.ssh/authorized_keys
mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
5、将私钥id_rsa拷贝到客户机
A:linux下可以拷贝到/root/.ssh/就可以直接使用了。

三、SSH服务的配置
1、配置SSH服务的运行参数,是通过修改配置文件/etc/ssh/sshd_config实现的。
2、因为SSH服务使用默认的配置已经能够很好的工作,如果仅仅提供SSH服务不需要修改。这里只介绍一
些常用的选项。
#Port 22
定义了SSH服务监听的断口号,SSH服务默认使用的端口号是22
#Proctocol 2,1
定义了SSH服务器使用SSH协议的顺序。默认识先使用SSH2协议,如果不成功则使用SSH1协议,为了安全起
见,可以设置只使用SSH2协议。
#ListenAddress 0.0.0.0
定义SSH服务器帮定的IP地址,默认绑定服务器所有可用的IP地址.
#PermitRootLogin yes
定义是否允许管理员登陆
#PermitEmptyPasswords no
定义是否允许空密码登陆.

#PasswordAuthentication no
定义是否使用口令认证方式,如果准备使用公钥认证可以设置为no

四 :
   吧 id_rsa ,拷到客户端,在服务器端吧id_rsa.pub 改名为authorized_keys

cat id_rsa.pub >> authorized_keys

linux ssh key配置方法的更多相关文章

  1. GitHub的SSH key配置以及常用的git命令介绍

    一. GitHub的SSH key配置 (以windows为例,Mac iOS系统类似) SSH Key 是一种方法来确定受信任的计算机,从而实现免密码登录.Git是分布式的代码管理工具,远程的代码管 ...

  2. 我的Python成长之路---GitHub使用克隆GitHub(SSH key配置)

    六.克隆GitHub仓库 1.创建仓库目录,目录位置没有要求,比如D:\learngit. 2.配置ssh(如果不配置会每次都输入用户名和密码) 使用TortoiseGit生成ssh-key:开始菜单 ...

  3. 【Python】Linux crontab定时任务配置方法(详解)

    CRONTAB概念/介绍 crontab命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行. cron 系统调度进程. 可以使用它在 ...

  4. Mac多SSH Key配置

    多SSH key配置 工作的时候碰到SSH配置的问题,就是公司用的是gittea的仓库,而本人的github平常也要使用,这个时候就需要配置不同的SSH key了.将同一个公钥分配配置给github和 ...

  5. git ssh key配置&解决git每次输入密码

    git ssh key配置&解决git每次输入密码:https://blog.csdn.net/qq_42817227/article/details/81415404

  6. 多个ssh key 配置多个网址

    多个 ssh key 配置多个网站 一.生成ssh key ssh-keygen -t rsa -C "你的邮箱" -f ~/.ssh/id_rsa_one ssh-keygen ...

  7. linux免密登录ssh验证配置方法及常见错误解决

    目标:从服务器A免密登录服务器B [配置方法] 1.在服务器A生成密钥文件,直接使用以下命令: ssh-keygen 中间遇到输入内容一路回车即可,完成后会在 ~/.ssh 目录下生成两个文件:id_ ...

  8. 多个 git ssh key 配置 Ubuntu os

    1.生成ssh key: ssh-keygen -t rsa -C “email@sss.com” 此时,在~/.ssh/文件夹下会有两个文件, id_rsa 和 id_rsa.pub.分别保存ssh ...

  9. win7生成ssh key配置到gitlab

    测试服务上使用ip访问gitlab,比如http://192.168.0.2/,创建用户并登陆后创建一个项目,比如git@gitlab.demo.com:demo/helloworld.git 如果想 ...

随机推荐

  1. mysql同一台服务器上不同数据库中个别表内容同步

    >>>>>>soft_wsx>>>>>>--数据备份与还原>>同步备用服务器--1.完全备份主数据库--2.使用带S ...

  2. Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  3. MapReduce 程序运行报错 java.lang.ClassNotFoundException解决方法

    在创建自定义的Mapper时候,编译正确,但上传到集群执行时出现错误: 11/16/05 22:53:16 INFO mapred.JobClient: Task Id : attempt_20111 ...

  4. ios 转发一篇对于6 plus的分辨率模式的说明

    http://segmentfault.com/q/1010000002545515 分为兼容模式和高分辨率模式. 兼容模式 当你的 app 没有提供 3x 的 LaunchImage 时,系统默认进 ...

  5. 【python】利用pathlib遍历目录Path().rglob

    来源:https://docs.python.org/3/library/pathlib.html 可以用pathlib模块中的Path().rglob来递归遍历文件 from pathlib imp ...

  6. window.parent 与 window.opener

    window.parent针对iframe,window.opener针对window.open 父页面parent.jsp: <%@ page language="java" ...

  7. centos 6.5 配置LDAP服务器+客户端!

    各种度娘!各种歌哥!网上教程参差不齐,历时1天,终于完成,不敢独享,遂,总结分享之,有问题可以留言,知无不言...开始吧 Note: 本次配置的服务器环境是<redhat enterprise ...

  8. CodeSign error: code signing is required for product type Application in SDK iOS

    在真机测试的时候往往会突然出现这样一个错误,code signing is required for product type 'Application' in SDK 'iOS 7.0'  ,就是说 ...

  9. Servlet题库

    一.    填空题 Servlet中使用Session对象的步骤为:调用  HttpServletRequest.getSession()  得到Session对象,查看Session对象,在会话中保 ...

  10. [Java 基础] 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法

    reference : http://www.cnblogs.com/linjiqin/archive/2013/05/30/3108188.html 在Java多线程应用中,队列的使用率很高,多数生 ...