第2步:配置openssh服务器
默认配置文件:
/etc/ssh/sshd_config
打开配置文件进行更改:
sudo nano /etc/ssh/sshd_config
以#开头的行表示注释:
# $OpenBSD: sshd_config,v 1.100 2014/08/15 12:32:04 naddy Exp $ # This is the sshd server system-wide configuration file. See # default value. Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: # Authentication: #LoginGraceTime 2m #PermitRootLogin prohibit-password #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #PubkeyAuthentication yes # Expect .ssh/authorized_keys2 to be disregarded by default in future. #AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 #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 # Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no # GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes PrintMotd no #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #UsePrivilegeSeparation sandbox #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #UseDNS no #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # Allow client to pass locale environment variables AcceptEnv LANG LC_* # override default of no subsystems Subsystem sftp /usr/lib/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server
第3步:进行基本的修改
OpenSSH默认设置允许密码身份验证。
要禁用,请将行更改为:
PasswordAuthentication no
要完全禁用root用户,请将行更改为:
PermitRootLogin no
默认情况下,root用户没有密码设置,它会自动禁用该帐户。
但是当在root帐户上设置密码时,如果PermitRootLogin没有禁用,那么root将可以通过ssh登录。
修改后,需要重新启动OpenSSH服务器使设置生效。
sudo systemctl restart ssh
第1步:安装OpenSSH服务器
通过运行下面的命令,可以在Ubuntu上安装OpenSSH服务器。
sudo apt-get update sudo apt-get install openssh-server openssh-client
上面的命令将安装服务器并配置其默认设置,其中有帐户访问的人可以使用有效密码登录系统。
这是作为密码身份验证。
除root用户外,任何人都可以使用有效的帐户名称和密码登录。
日期:2020-07-07 20:55:51 来源:oir作者:oir