标签:配置 sshd_conf mct stat listen inter padding name data
SSH(Secure Shell)使用加密方式传输数据,相比其他使用明文传输的远程登录方式具有更高的安全性。
ssh允许使用两种验证方式登录:密码验证,密钥验证
系统版本:Ubuntu 18.04.2LTS
openssh-server 版本:1:7.6p1-4ubuntu0.3
安装ssh:sudo apt install openssh-server
更改全局配置文件sshd_config :nano /etc/ssh/sshd_config
端口:去掉 Port 22
一项前的#
,若使用其他端口,把 22 更改为相应端口。
密码验证:去掉 PasswordAuthentication yes
一项前的#
,并确保此项是yes而不是no。
其他选项(可选):
ListenAddress 0.0.0.0:定义服务端绑定的ip,默认绑定所有可用ip
PermitRootLogin prohibit-password:允许root用户登录
检查sshd服务是否已启动:systemctl status sshd
,若未启动则:systemctl start sshd
开机启动:systemctl enable sshd
查看主机地址:ip address
,找到相应的网卡,记下inet 后的ip
连接至服务器:ssh -p port user@server-address
,server-address即上面记下的ip,- p 选项用于指定端口
客户端可以在配置文件中存储常用选项和常用主机:
~/.ssh/config
# global options
User user
?
# host-specific options
Host myserver
HostName server-address
Port port
进行了如上的配置后,以下命令是等效的
$ ssh -p port user@server-address
$ ssh myserver
安装ssh:sudo apt install openssh-server
更改全局配置文件sshd_config :nano /etc/ssh/sshd_config
端口:去掉 Port 22
一项前的#
,若使用其他端口,把 22 更改为相应端口。
公钥验证:去掉 PubkeyAuthentication yes
一项前的#
,并确保此项是yes而不是no。
启用公钥文件:去掉 AuthorizedKeysFile
一项前的#
创建公钥文件:touch ~/.ssh/authorized_keys
,注意检查该文件的权限是否为600。
其余步骤同上。
生成密钥:ssh-keygen -t rsa
注:当要求输入文件名时(Enter file in which to save the key)请使用绝对路径,否则密钥将生成在当前目录,若使用默认路径则直接回车
到相应文件夹找到xxx.pub, xxx两个文件,xxx放置于~/.ssh/文件夹下,xxx.pub上传到服务端,并将其中内容追加到服务端的公钥文件中,(永远只把公钥交给服务器)
如:cat xxx.pub >> ~/.ssh/authorized_keys
使用ssh -p port user@server-address
命令登录即可
端口一定要更改,因为22端口与Windows的默认ssh服务冲突,需更改为其他端口
标签:配置 sshd_conf mct stat listen inter padding name data
原文地址:https://www.cnblogs.com/gotolearn/p/ssh.html