surroundings
Virtual Machine installed operating system version: CentOS Linux release 7.6.1810 (Core)
Creating ssh login user
Log in with administrator privileges
Create a user
adduser mytestssh
set password
passwd mytestssh
Give sudo privileges
gpasswd -a mytestssh wheel
-a: Add users to the target group
wheel: the meaning of the steering wheel, a special group of users in linux. Because the root user is very dangerous, so users will need administrator privileges to add to the group, so that the user can use the sudo command.
Under Administrator user query packet
lid -g wheel
If we can show the user to add, the above operations are successful.
Rsa key initialization
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Instruction will be prompted to enter information, select the appropriate information to fill, can not fill the whole, has been the Enter skip setting.
Open ssh configuration file
vi /etc/ssh/sshd_config
Found in the file
#PermitRootLogin yes
PermitRootLogin yes
value Whether to allow ssh landing Login Method shell command yes Yes Unlimited Unlimited without-password Yes You can not log on with a password Unlimited forced-commands-only Yes You can only log in with a key You can only have been authorized by the command no no There are four values PermitRootLogin
save document
In front of the # removed.
Start ssh service
systemctl start sshd.service
Check the ssh service is started successfully
ps -e | grep sshd
ss -pltn | grip 22
It can be seen listening port
You can see the process, and then check port
Check whether the network is turned on
ip addr
Usually have more than one address, the name of the local lo card. If there is no other name card ip address, it is turned off.
Start card
nmtui
After this instruction, select the corresponding card, to activate a carriage return.
Virtual machines can not ping
原因可能是虚拟机网络设置的为NAT模式。如果继续使用NAT模式需要配置端口转发。也可用仅主机能访问的模式。
这里我们修改为桥接模式。然后检查网卡的IP是不是在同一网段。
ssh连接
ssh [email protected]
证书提示选择yes。密码输入正确后进入到虚拟机中。
其他指令
查看系统版本
cat /etc/centos-release