Sshd

RHEL 7 SSH 服務 開始 停止 重啟

  • August 7, 2019

對不起這個非常基本的問題。

我在一家非常小的公司擔任開發人員,我們正在努力幫助基礎設施團隊建立一個新環境。

我們正在從 RHEL 5 32 位遷移到 RHEL 7 64 位。

我們可以正確安裝和參數化 SSH 的安裝。

一切正常,除了當我們停止、啟動或重新啟動服務時我將稱之為“輸出標籤”。請參閱下面的照片以獲得更好的理解。我的意思是

$$ OK $$,$$ FAILED $$例如,在使用 service sshd restart 後出現在螢幕上。 照片只是顯示標籤的範例。

在此處輸入圖像描述

在 RHEL 5 上,它完美無缺。

在 RHEL 7 上它可以工作,但我沒有相同的輸出(

$$ OK $$,$$ FAILED $$, ETC) 我想我錯過了一些東西。

在 google 上進行了搜尋,但找不到與此相關的任何內容。

無法為 systemd 啟用該類型的輸出:https ://bugzilla.redhat.com/show_bug.cgi?id=1148571

但是,它肯定會讓您知道它是否失敗以及如何檢查有關失敗原因的更多資訊。

回到 Redhat 5(和 6),那是使用/etc/init.d. Redhat 7 使用systemd,您可以用餘下的時間在網上搜尋並閱讀比較它們的差異、優點、缺點等的文章。

你以前做的

/etc/init.d/sshd status
/etc/init.d/sshd start
/etc/init.d/sshd stop
/etc/init.d/sshd restart

or you may be more familiar with     service sshd <start|stop|restart|status>

在 RHEL 7 你做

systemctl status sshd
systemctl start sshd
systemctl stop sshd
systemctl restart sshd

service sshd <start|stop|restart|status> will also work but you'll get an info statement saying "redirecting to /bin/systemctl"

systemctl status sshd可能會讓你知道什麼是錯的;以及查找/var/log/messages報告的錯誤。

在 RHEL 7.x(和許多其他 linux)中,伺服器上的 SSHd 在文件中配置/etc/ssh/sshd_config。您需要查看此文件並確保設置正確,因為(a)如果沒有,那麼服務將無法啟動,並且將由systemctl 狀態報告,以及(b)如果服務確實以綠色啟動了 OK 你仍然可能無法 ssh 進入您的系統。

這是預設值/etc/ssh/sshd_config,實際上來自 Centos 7.6,但應該與 RHEL 7.6 完全相同;如果您的 SSH 服務無法啟動,那麼您可以嘗試將現有的sshd_config備份到*/etc/ssh/sshd_config_old並使用這個;如果 sshd 服務仍然無法啟動,那麼這不是sshd_config*文件問題,因為這是 RHEL/Centos 7 安裝附帶的預設設置,適用於新安裝的每個人。

#   $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

# 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.

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#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
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users 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'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

# override default of no subsystems
Subsystem   sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   X11Forwarding no
#   AllowTcpForwarding no
#   PermitTTY no
#   ForceCommand cvs server

引用自:https://unix.stackexchange.com/questions/534360