ssh的配置,ssh打开密钥登陆,关闭密码登陆。
刚装玩fedora,那么我们就以fedora为例来说一下怎么配置:
1、先确认是否已安装ssh服务:
[root@localhost ~]# rpm -qa | grep openssh-server
openssh-server-5.3p1-19.fc12.i686 (这行表示已安装)
若未安装ssh服务,可输入:
#yum install openssh-server
进行安装
2、winscp登陆,用root密码登陆。
3、修改配置文件:
#vi /etc/ssh/sshd_config
winscp登陆的话,就直接修改/etc/ssh/sshd_config
找到AuthorizedKeysFile .ssh/authorized_keys
这就是存在服务器上的公钥文件,一行一个。
自己创建一下
完整路径是 /root/.ssh
在winscp下要用一下手动打开(ctrl+o),.ssh隐藏了,打开路径/root/.ssh
如果不存在,就在root下手动创建一个.ssh文件夹
新建文件,复制你的公钥那行保存
找到:PasswordAuthentication yes
允许密码登陆,改为no,禁止密码登陆。
下面是对SSH配置文件的一些选项的分解说明,ssh_config是OpenSSH客户端的配置文件,sshd_config是OpenSSH服务器端的配置文件。 ssh_config的内容如下: # This is the ssh client system-wide configuration file. See ssh_config(5) for more information. This file provides defaults for users, and the values can be changed in # er-user configuration files or on the command line. # Configuration data is parsed as follows: // 配置选项生效的优先级
# 1. command line options // 命令行选项
# 2. user-specific file // 用户指定文件
# 3. system-wide file // 系统范围的文件
# Any configuration value is only changed the first time it is set. Thus, host-specific definitions should be at the beginning of the configuration file, and defaults at the end. # Site-wide defaults for some commonly used options. For a comprehensive list of available options, their meanings and defaults, please see the ssh_config(5) man page. Host * // 使用的计算机范围,'*'表示全部
# ForwardAgent no // 设置连接是否经过验证代理(如果存在)转发给远程计算机
# ForwardX11 no // 设置X11连接是否被自动重定向到安全的通道和显示集
# ForwardX11Trusted yes // 是否允许转发X11会话
# RhostsRSAAuthentication no // 设置是否使用RSA进行rhosts的安全验证
# RSAAuthentication yes // 设置是否使用RSA进行安全验证
# PasswordAuthentication yes // 设置是否需要口令验证
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# GSSAPIKeyExchange no
# GSSAPITrustDNS no
# BatchMode no // 如果为yes,则交互输入口令时的提示(passphrase/password的提示)信息将被禁止
# CheckHostIP yes // 设置SSH是否查看连接到服务器的主机的IP地址以防止DNS欺骗。建议设置为yes
# AddressFamily any
# ConnectTimeout 0
# StrictHostKeyChecking ask // 如果设置成yes,SSH就不会自动把计算机的密钥加入$HOME/.ssh/known_hosts文件,并且一旦计算机的密匙发生了变化,就拒绝连接
# IdentityFile ~/.ssh/identity
# IdentityFile ~/.ssh/id_rsa // RSA安全验证文件的位置
# IdentityFile ~/.ssh/id_dsa // DSA安全验证文件的位置
# Port 22 // 服务器端口
# Protocol 2,1 // 使用的SSH协议
# Cipher 3des // 设置加密的方式
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
# EscapeChar ~ // 设置Escape(转义)字符
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p gateway.example.com
SendEnv LANG LC_* // 局部环境变量
HashKnownHosts yes
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no sshd_config的内容如下: # Package generated configuration file See the sshd_config(5) manpage for details # What ports, IPs and protocols we listen for
Port 22 // sshd的监听端口号,默认为22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0 // 设置sshd服务绑定的IP地址,0.0.0.0表示侦听所有地址
Protocol 2 // 默认只使用2.*版本的SSH协议
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key // SSH2版本的RSA密钥存放位置
HostKey /etc/ssh/ssh_host_dsa_key // SSH2版本的DSA密钥存放位置
HostKey /etc/ssh/ssh_host_ecdsa_key // SSH2版本的ECDSA密钥存放位置
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes # Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600 // 密钥每隔1小时生成一次
ServerKeyBits 768 // SSH服务器密钥的位数 # Logging
SyslogFacility AUTH // 设置sshd发送到syslog所使用的日志类型
// 设置在记录来自sshd的消息时是否给出facility code
LogLevel INFO // syslog日志级别 # Authentication:
LoginGraceTime 120 // 设置如果用户不能成功登录,sshd将会在这个配置参数指定的时间过后断开连接(单位为秒)
PermitRootLogin yes // 如果为yes则允许root用户使用ssh登录,为no则表示不允许root进行ssh登录
StrictModes yes // 设置sshd在接受登录请求前是否检查用户的主目录以及rhosts文件的权限和所有者等信息。防止目录和文件设成任何人都有写权限 RSAAuthentication yes // 是否允许RSA验证
PubkeyAuthentication yes // 是否允许公钥验证
AuthorizedKeysFile %h/.ssh/authorized_keys// 公钥文件存放的位置 # Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes // 验证时是否使用'~/.rhosts'和'~/.shosts'文件
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no // 设置是否允许用rhosts或/etc/hosts.equiv加上RSA进行安全验证
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes // 设置sshd在进行RhostsRSAAuthentication安全验证时是否信任用户的'~/.ssh/known_hosts'文件 # To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no // 设置是否允许用空口令登录 # Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no // 设置是否允许使用提示/应答式认证。sshd支持login.conf文件中定义的所有认证类型 # Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes // 设置是否需要口令验证,默认为yes # Kerberos options // Kerneros验证
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes # GSSAPI options // GSSAPI 验证
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes // 清除验证信息 X11Forwarding yes // 设置sshd是否允许X11转发,默认为允许
X11DisplayOffset 10
PrintMotd no // 设置sshd是否在用户登录时显示/etc/motd中的信息
PrintLastLog yes // 交互式登录时是否输出用户上次登录的日期和时间
TCPKeepAlive yes // TCP活动保持
#UseLogin no // 指定login命令是否可用于交互式登录会话 #MaxStartups 10:30:60
#Banner /etc/issue.net // 设置保存banner信息的文件位置,用户登录后会显示该banner信息 # Allow client to pass locale environment variables
AcceptEnv LANG LC_* // 指定客户端发送的那些环境变量能后复制到当前会话的运行环境(客户端需要设置其配置文件ssh_config中的SendEnv参数) Subsystem sftp /usr/lib/openssh/sftp-server // 用于配置一个外部的服务程序,如文件传输服务器sftp-server。配置参数的值应该是一个系统名与命令,能够基于客户系统的请求开始运行。sftp-server命令实现了sftp文件传输子系统。这个配置参数仅使用与SSH2 # 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'. UsePAM yes // 是否启用PAM插件式认证模块,默认为yes
关于配置文件的详细说明,留着,不用看。
禁止了密码登陆,设置了公钥。
重启sshd,在终端窗口运行:
systemctl restart sshd.service
可以配置winscp用私钥登陆了。
ssh的配置,ssh打开密钥登陆,关闭密码登陆。的更多相关文章
- 安装SSH,配置SSH无密码登陆
环境:ubuntu16.04 Ubuntu 默认已安装了 SSH client,所以我们还需要安装 SSH server: sudo apt-get install openssh-server 安装 ...
- 安装SSH、配置SSH无密码登录 ssh localhost
集群.单节点模式都需要用到 SSH 登陆(类似于远程登陆,你可以登录某台 Linux 主机,并且在上面运行命令),Ubuntu 默认已安装了 SSH client,此外还需要安装 SSH server ...
- Linux密钥登录原理和ssh使用密钥实现免密码登陆
目录 1. 公钥私钥简介 2. 使用密钥进行ssh免密登录 2.1. 实验环境 2.2. 开始实验 3. ssh的两种登陆方式介绍 3.1. 口令验证登录 3.2. 密钥验证登录 4. 总结 1.公私 ...
- linux ssh密钥认证, 免密码登陆
1. 客户端生成密钥 # mkdir ~/.ssh # chmod ~/.ssh # cd ~/.ssh 生成RSA密钥 # ssh-keygen -t rsa (然后连续三次回车) 2. 把公钥传到 ...
- 数据库sqlserver2008登陆名密码登陆不了怎么办?
我用的是sql server2008数据库,原先创建的登录名是sa,但是密码就忘了.总是出现这个连接问题
- 问答项目---登陆账号密码登陆做AJAX异步校验
异步验证管理员帐号方法: /* 异步验证管理员帐号 */ public function checkAccount(){ if(!IS_AJAX){echo "页面不存在";die ...
- Xshell配置SSH免密码登录
思路: 私钥存放于客户端,id_rsa 将客户端公钥存放于要远程控制服务器上:将客户在公钥id_rsa.pub内容追加到 /root/.ssh/authorized_keys 使用密钥认证分3步: 1 ...
- 为git配置ssh
git clone有两种方式,一种是http,一种是ssh. 配置ssh的好处是:在每次push代码的时候不需要输入密码. bash上生成秘钥: ssh-keygen -t rsa -C " ...
- Windows上安装配置SSH教程(3)——在Windows系统上安装与配置WinSCP
知识点汇总:http://www.cnblogs.com/feipeng8848/p/8559803.html -------------------- 首先确认客户端已经安装了OpenSSH.安装方 ...
随机推荐
- Python的递归
递归 是指函数/过程/子程序在运行过程序中直接或间接调用自身而产生的重入现象.在计算机编程里,递归指的是一个过程:函数不断引用自身,直到引用的对象已知.使用递归解决问题,思路清晰,代码少.但是在主流高 ...
- ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(尺取)题解
题意:n个城市,初始能量c,进入i城市获得a[i]能量,可能负数,去i+1个城市失去b[i]能量,问你能不能完整走一圈. 思路:也就是走的路上能量不能小于0,尺取维护l,r指针,l代表出发点,r代表当 ...
- 【镜像地址】Maven地址列表
1.国内OSChina提供的镜像,非常不错 <mirror> <id>CN</id> <name>OSChina Central</name> ...
- Luogu USACO Training 刷水记录
开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...
- Unity3D学习笔记(二十三):事件接口、虚拟摇杆、层级管理和背包系统
事件接口 IDragHandler(常用):鼠标按下拖动时执行(只要鼠标在拖动就一直执行) IDropHandler:对象拖动结束时,如果鼠标在物体的范围内,执行一次(依赖于IDragHandler存 ...
- .Net Core集成Office Web Apps(一)
最近开始学习.Net Core,并使用Visual Studio Code工具来开发.感觉开发起来特别的方便,但是有个头疼的地方:许多的类库被修改了,一时半会儿还熟悉不了,需要查阅官方API... M ...
- Ubuntu更新软件源出现GPG error
原因 在sources.list文件中加入了非ubuntu官方源,所以认为加入源是不可信任的. 解决方法导入该源公钥.E084DAB9为PUBKEY后八位 gpg --keyserver keyser ...
- 中文名文件上传到linux服务器上以后文件名会乱码(openoffice)
1.中文名文件上传后保存在linux服务器上文件名会乱码,但是我们通过SSH直接对服务器上的一个文件进行重命名是可以使用中文的,而且显示出来是正确的,这说明服务器是可以支持中文的. 2.而为什么上传的 ...
- Spring AMQP 源码分析 08 - XML 配置
### 准备 ## 目标 通过 XML 配置文件使用 Spring AMQP ## 前置知识 <Spring AMQP 源码分析 07 - MessageListenerAdapter> ...
- mapStateToProps,mapDispatchToProps的使用姿势
本文作者:IMWeb 黄qiong 原文出处:IMWeb社区 未经同意,禁止转载 前言 刚接触redux的时候,发现大家对mapDispatchToProps使用有几种方法,而且都跑通了,本文来介绍下 ...