CentOS SSH安全和配置無密碼登錄


  1. 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。

 

 

 

  1. 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 ~]#


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM