![Ubuntu 16.04 中的 OpenSSH 服务器](https://linux22.com/image/925129/Ubuntu%2016.04%20%E4%B8%AD%E7%9A%84%20OpenSSH%20%E6%9C%8D%E5%8A%A1%E5%99%A8.png)
连接服务器时出现问题
我可以 ping 服务器(Ubuntu 服务器 16.04 无 GUI),服务器可以 ping 桌面(Ubuntu 18.04)。我在桌面计算机上安装了 Openssh-server 7.6p1。服务器安装没有 GUI,Openssh 版本是 有一个以太网适配器插入服务器 USB。没有电缆,只有一个启用的收发器与 wifi 路由器通信。到目前为止一切顺利,但如果我按如下方式 ssh 服务器,它每次都会默认为客户端。
root@xxxdesktop:/home/andycc# ssh -i /root/.ssh/id_rsa [email protected] -v -p
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to xxxserver.xxxhome.net [x.x.x.7] port nn
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to xxxserver.xxxhome.net:54219 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:5Irn4Yn4FkYwxAouW41TYIWe9duri4WoOdFjd2Sk51o
debug1: checking without port identifier
debug1: Host 'xxxserver.xxxhome.net' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:9
debug1: found matching key w/out port
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:ZwS+vr6fZV5+uA36BIAwA0h7lYwrK7K4mrpscSx+7rE /root/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to xxxserver.ubuntuhome.net (x.x.x.7]:54219).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-99-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
5 packages can be updated.
5 updates are security updates.
Last login: Mon May 11 21:06:41 2020 from 192.168.0.4
-----------------------------------------------------------------------------------------------
我在客户端和服务器上设置了所有权和权限,如下所示:
root@vostro230desktop:~#
home/androo/.ssh $ chown androo:androo -R home/androo/.ssh (server)
home/androo/.ssh $ chmod 600 *
home/androo $ chmod 700 .ssh
root@xxxdesktop:/home/androo# ls -al .ssh
drwx------ 2 androo androo 4096 May 10 13:02 .
drwxr-xr-x 17 androo androo 4096 May 10 20:59 ..
-rw------- 1 androo androo 1628 May 10 13:02 authorized_keys
-rw------- 1 androo androo 1679 May 10 15:52 id_rsa
-rw------- 1 androo androo 403 May 10 15:52 id_rsa.pub
-rw------- 1 androo androo 2870 May 10 20:40 known_hosts
-rw------- 1 androo androo 617 May 11 01:29 known_hosts.old
类似地,我在客户端和服务器上都设置了根目录的权限,如下所示
root/.ssh $ chown root:root -R root/.ssh
root/.ssh $ chmod 600 *
root/ $ chmod 700 .ssh
这是客户端的所有权和权限设置,除了用户名外,它与服务器配置相同。
home/andycc/.ssh $ chown andycc:andycc -R home/andycc/.ssh (client)
home/andycc/.ssh $ chmod 600 *
home/andcc $ chmod 700 .ssh
root@xxxdesktop:/home/andycc# ls -al .ssh
drwx------ 2 andycc andycc 4096 May 10 13:02 .
drwxr-xr-x 17 andycc andycc 4096 May 11 20:59 ..
-rw------- 1 andycc andycc 1628 May 10 13:02 authorized_keys
-rw------- 1 andycc andycc 1679 May 8 15:52 id_rsa
-rw------- 1 andycc andycc 403 May 8 15:52 id_rsa.pub
-rw------- 1 andycc andycc 2870 May 11 20:40 known_hosts
-rw------- 1 andycc andycc 617 May 8 01:29 known_hosts.old
Ubuntu 18.04桌面客户端上的etc/ssh/ssh_config文件选项如下:
Host x.x.x.x
CheckHostIP yes
StrictHostKeyChecking no
IdentityFile /root/.ssh/id_rsa
Port 54xxx
Protocol 2
PasswordAuthentication no
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes
服务器的 sshd_config 文件选项如下:
port 54nnn
protocol 2
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
Use PrivilegeSeparation yes
KeyRegenerationInterval 3800
ServerKeyBits 1024
SyslogFacility AUTH
Loglevel INFO
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
AllowUsers andyccc
RSAAuthentication no
PubKeyAuthentication yes
AuthorizedKeysFile root.ssh/authorized_keys
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
PasswordAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
Accept LANG
Subsystem stp/usr/lib/…
UsePAM yes