CentOS SSH安全和配置无密码登录
CentOS ssh默认监听端口 22端口,允许root用户ssh登录。server投入生产后很有必要更改默认ssh监听端口和禁止root登录。
步骤1:确认安装有ssh包
[appuser@su172 ~]$ rpm -qa | egrep -i ssh
openssh-server-5.3p1-114.el6_7.x86_64
openssh-5.3p1-114.el6_7.x86_64
libssh2-1.4.2-1.el6.x86_64
步骤2:可以进一步确认包的默认安装位置信息
appuser@su172 ~]$ rpm -qpl openssh-server-5.3p1-114.el6_7.x86_64
步骤3:主要改动这2个项
[root@su172 ~]# egrep '^Port|^PermitRoot' /etc/ssh/sshd_config
Port 3001
PermitRootLogin no
[root@su172 ~]#
步骤4:重启sshd服务
service sshd restart
步骤5:确认监听端口,客户端验证测试。
#装有ssh 客户端软件,例如Xmanager
ssh 192.168.36.182 3001
#在Linux Server上,可以这样子登录
ssh 192.168.36.182 -p 3001 -l appuser
#示例
[root@su172 ~]# netstat -antlp | egrep -i ssh
tcp 0 0 0.0.0.0:3001 0.0.0.0:* LISTEN 1528/sshd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 1586/sshd
tcp 0 52 192.168.36.182:3001 192.168.36.36:34834 ESTABLISHED 1582/sshd
tcp 0 0 :::3001 :::* LISTEN 1528/sshd
tcp 0 0 ::1:6010 :::* LISTEN 1586/sshd
[root@su172 ~]#
#用w或者who确认
[root@su172 ~]# w
23:09:56 up 1:00, 3 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - 22:10 14.00s 0.16s 0.16s -bash
appuser pts/0 192.168.36.36 23:04 0.00s 0.10s 0.15s sshd: appuser [priv]
appuser pts/1 192.168.36.181 23:07 2:12 0.01s 0.01s -bash
[root@su172 ~]#
扩展:端口
公认端口(Well Known Ports)从0到1023。
注册端口(RegisteredPorts)从1024到49151。
动态和/或私有端口(Dynamic and/or Private Ports)从49152到65535。
CentOS系统之间有可能需要无密码验证登录,方便拷贝东东,例如oracle rac安装时就有这个东西。所以提前了解很有必要。
node1执行以下步骤:
ssh-keygen -t rsa -P ''
scp /root/.ssh/id_rsa.pub root@192.168.36.182:/root/.ssh/id_rsa.pub181
node2执行以下步骤:
ssh-keygen -t rsa -P ''
scp id_rsa.pub root@192.168.36.181:/root/.ssh/id_rsa.pub182
node1执行:
cat id_rsa.pub182 >>authorized_keys
node2执行
cat id_rsa.pub181 >>authorized_keys
验证
node1验证
ssh 192.168.36.182
node2验证
ssh 192.168.36.181
扩展
-v跟踪
[root@su171 .ssh]# ssh -v 192.168.36.182
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.36.182 [192.168.36.182] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: Remote
protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.36.182' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address
debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address
debug1: Unspecified GSS failure. Minor code may provide more information
debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Thu May 12 23:51:22 2016 from 192.168.36.181
[root@su172 ~]#
CentOS SSH安全和配置无密码登录的更多相关文章
- centos ssh免密码秘钥登录
假设从A主机ssh登录B主机,用秘钥代替密码,步骤如下: 1.在A主机上执行:ssh-keygen -t rsa 一切默认,不用输入密码,生成两个文件: /root/.ssh/id_rsa /roo ...
- ssh配置无密码登录
1.在master机器上生成公钥: [root@master ~]# ssh-keygen -t rsa 注:一直按enter键就可以生成了 Generating public/private ...
- ssh 配置无密码登录
下框中在管理机上运行: [root@master ~]# ssh-keygen -t rsa #它在/root/.ssh下生成id_rsa和id_rsa.pub两个文件 [root@master ~] ...
- CentOS SSH安装与配置
SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立在应用层和传输层基础上的安全协议. 传 统的网络服务程序, ...
- 如何在Linux上设置SSH密码以进行无密码登录(转)
ssh(secure shell)广泛用于远程登录Linux服务器.当我们使用ssh登录到远程系统时,它会提示输入密码,然后只允许我们登录到服务器.有时我们需要配置应用程序或脚本(主要是shell脚本 ...
- 通过yum在centos安装mysql并配置远程登录
前言 前天按照Oracle上的文档装了一遍mysql,选了最新8.0的版本,后来出现一些问题,网上搜答案,出来的基本还是5.x版本的解决方案,并不适用8.0版本.然后我就去看了一下公司的正式环境买的阿 ...
- Linux记录-配置无密码登录
1.互信的机器都执行 ssh-keygen -t rsa cat ~/.ssh/id_rsa.pub >> /home/hdfs/.ssh/authorized_keys chmod 60 ...
- ubuntu配置无密码登录
1 本地生成ssh公钥和私钥, 2将公钥拷贝到ubuntu上的.ssh/authorized_keys 中
- CentOS 7 实现ssh无密码登录
cd ~ 进入根目录. (使用ls -a或者 ls -la 能够看到当前文件夹下的所有文件包含隐藏文件夹等) 我们首先使用ls -la 发现并没有.ssh的文件夹存在. 在终端输入 ssh lo ...
随机推荐
- 删除指定路径下指定天数之前(以文件的最后修改日期为准)的文件:BAT + VBS
代码如下: @echo off ::演示:删除指定路径下指定天数之前(以文件的最后修改日期为准)的文件. ::如果演示结果无误,把del前面的echo去掉,即可实现真正删除. ::本例调用了临时VBS ...
- [Luogu P2014]选课 (树形DP)
题面 传送门:https://www.luogu.org/problemnew/show/P2014 Solution 这是一道十分经典的树形DP题,这种类型的树形DP有一种很普遍的解法. 首先,观察 ...
- 基于虚拟机安装Linux并利用LVM创建磁盘分区
主要步骤:将磁盘设置为LVM类型,并在这四个分区上创建物理卷.卷组和逻辑卷,最后将逻辑卷挂载.电脑使用Windows10 企业版 LTSC 操作系统.虚拟机使用VMware15.5 pro . 1.安 ...
- 动态规划入门——动态规划与数据结构的结合,在树上做DP
本文由TechFlow原创,本博文仅作为知识点学习,不会用于任何商业用途! 今天我们来看一个有趣的问题,通过这个有趣的问题,我们来了解一下在树形结构当中做动态规划的方法. 这个问题题意很简单,给定一棵 ...
- 浅谈OpenGL之DSA
今天准备写一篇文章简单介绍一下OpenGL4.5引入的一个新的扩展ARB_direct_state_access,这个扩展为OpenGL引入了一个新的特性就是Direct State Acess,下文 ...
- 直播平台源码搭建教程:微信小程序中的直播如何去掉水印
直播平台源码搭建教程:微信小程序中的直播如何去掉水印 本文与大家分享一下直播平台源码搭建教程,如何去掉直播视频的水印 var services = require('../../lib/service ...
- inno setup win10 创建菜单里面卸载图标
1.win10自己注册表关联的卸载图标 会隐藏 卸载图标.现在的项目法是 不写注册表 直接 在目标文件里面创建快捷方式 移动到菜单里面 ; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 ...
- java联系人管理系统简单设计
本文实例为大家分享了java联系人管理系统毕业设计,供大家参考,具体内容如下 要求: 请使用XML保存数据,完成一个联系人管理系统. 用户必须经过认证登录后方可以使用系统. 注册 ...
- Python基本数据类型与数据结构(数据挖掘学习)
前言 最近工作和研究涉及到数据挖掘和机器学习,出于归纳和总结知识的目的写下这一系列的文章,这一系列文章将会包括Python的基本数据类型和数据结构,函数和面向对象相关的知识,然后会介绍数据挖掘和机器学 ...
- C\C++语言重点——指针篇 | 为什么指针被誉为 C 语言灵魂?(一文让你完全搞懂指针)
本篇文章来自小北学长的公众号,仅做学习使用,部分内容做了适当理解性修改和添加了博主的个人经历. 注:这篇文章好好看完一定会让你掌握好指针的本质! 看到标题有没有想到什么? 是的,这一篇的文章主题是「指 ...