openssh-server & openssh-clients
/etc/ssh/sshd_config Server端配置
- ClientAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the client,sshd will send a message through the encrypted channel to request a response from the client
The default is 0,indicating that these messages will not be sent to the client. - ClientAliveCountMax
Sets the number of client alive messages which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent,sshd will disconnect the client, terminating the session.
Default is 3. - UseDNS
是否开启反向解析,最好设为no - Banner /etc/issue.net
显示/etc/issue.net内容,输入password前显示,无转义 - PrintMotd yes
打印 /etc/motd,登录后显示 - PrintLastLog
interactvie登录时,打印最后一次的登录时间 - DenyUsers u1 u2 => AllowUsers => DenyGroups => AllowGroups
这个指令后面跟着一串用空格分隔的组名列表(其中可以使用"*"和"?"通配符)。默认允许所有组登录。
如果使用了这个指令,那么将仅允许这些组中的成员登录,而拒绝其它所有组。
这里的"组"是指"主组"(primary group),也就是/etc/passwd文件中指定的组。
这里只允许使用组的名字而不允许使用GID。相关的 allow/deny 指令按照下列顺序处理: - GatewayPorts
是否允许远程主机连接本地转发端口,默认为 no
sshd默认将远程转发端口绑定到loopback,这样将阻止远程主机连接到转发端口,GatewatyPorts yes可以让sshd将远程端口转发绑定到非loopback地址,这样就允许远程主机连接至本机远程转发端口 - HostKey
主机私钥文件(group & others应该无任何权限)否则会出现下图错误
上图中私钥文件的指纹是一致的,只不过是权限原因
默认为:
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
这个文件的内容会出现在其他主机 ~/.ssh/known_hosts中
而源主机的的公钥位于/etc/ssh/ssh_host_ecdsa_key.pub文件中,格式为
/etc/ssh/下面还有对应的公钥,用于身份验证
默认使用的公钥为ecdsa格式
!!!!!!!!!!!!!!
默认我们都会使用ssh-keygen生成用户专属密钥对于 ~/.ssh下,用作pubkey,ssh默认也是于 ~/.ssh下寻找私钥,但是我们是可以使用 /etc/ssh/ssh_host_*_key 这些主机自带的密钥对ssh-copy-id -i /etc/ssh/ssh_host_ecdsa_key.pub -p 22 root@172.16.3.9
ssh -t -i /etc/ssh/ssh_host_ecdsa_key -l root 172.16.3.9
在进行连接的时候需要显式 使用 -i 指出私钥
- GSSAPIAuthentication
是否允许使用基于GSSAPI的用户认证 - ListenAddress
ListenAddress IP:port
未指定port,则使用Port指令的值,可指定多条ListenAddress指令 - LoginGraceTime
限制用户连接后,必须于指定时限内认证成功,默认 2m - MaxAuthTries
每个连接最大允许认证次数
MaxAuthTries 6
- MaxStartups
最多允许保持几个未认证的连接,到达限制后,将不再接受新连接,除非先前的连接认证成功 or 超出LoginGraceTime的限制
MaxStartups 10:30:100
- Subsystem
配置子系统
Subsystem sftp /usr/libexec/openssh/sftp-server - PubkeyAuthentication yes
启用公钥认证 - AuthorizedKeysFile .ssh/authorized_keys
保持连接设置:
ssh连接server后,如果一段时间不操作,再此进入Terminal会卡顿,后提示
Write failed: Broken pipe
解决办法:
- client端的配置文件 ~/.ssh/config中加入
ServerAliveInterval 60
- server端的配置文件/etc/ssh/sshd_config中加入
ClientAliveInterval 60
- 当前连接临时使用
ssh -o ServerAliveInterval=60 user@server
ssh 客户端选项:
- -l login_name 登录名
ssh -l root host
但是下面情况下,-l 无效
ssh -l user@host
- -T Disable pseudo-terminal allocation,不分配tty
默认登录interactive shell都会分配tty,使用此选项后,不会分配tty
使用w等也不会看到此登录信息
-
-t Force pseudo-terminal allocation, This can be used to execute arbitrary screen-based programs on a remote machine, which can be very userful, e.g. when implementing menu services
强制ssh连接时分配终端,主要用于ssh -l user host 'command'时不加 -t 时执行一些交互式命令会提示 TERM environment variable not set 或者 terminal unkown类似的提示
ssh -l root 172.16.3.8 -t 'watch -cen 2 ip a'
加入t即可正常运行
常见问题:
- Remote Host Identification Has Changed!
server端因为某种原因(重装系统,IP地址变更,DHCP,虚拟机重建,Middle Man Attack)该IP地址的公钥改变,就会发出该提示
ssh客户端不进行公钥确认
修改/etc/ssh/ssh_config文件
Host * StrictHostKeyChecking no
命令行
ssh -o StrictHostKeyChecking=no host
- 防止远程主机公钥改变导致ssh连接失败
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null host
-
ssh_exchange_identification: Connection closed by remote host
设置了/etc/hosts.deny,在/etc/host.allow放行相应主机
还有一种情况是server达到了最大连接数限制sshd:10.8.0.0/255.255.255.0:allow all:116.236.134.26:allow all:172.16.0.0/255.240.0.0:allow sendmail:all:allow
ssh-keygen:
OpenSSH使用的公钥格式不同于OpenSSL生成的公钥
我们需要使用ssh-keygen的 -y选项来生成OpenSSH专用公钥
-y This option will read a private OpenSSH format file and print OpenSSH public key to stdout
openssh第二步身份验证的时候,可以不依靠id_rsa.pub等公钥,但是当id_rsa私钥目录存在id_rsa.pub公钥时会优先使用id_rsa.pub
如果id_rsa.pub的格式不对,也不会使用,如果格式正确会使用id_rsa.pub
相关文章
- 解决Setting property 'source' to 'org.eclipse.jst.jee.server的问题
- PHP中获取当前页面的完整URL & php $_SERVER中的SERVER_NAME 和HTTP_HOST的区别
- SQL SERVER全面优化-------Expert for SQL Server 诊断系列
- 【数组&双指针】LeetCode 76. 最小覆盖子串【困难】
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
- connection to dat Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
- Ruby on Rails 3 Can't connect to local MySQL server through socket '/tmp/mysql.sock' on linux
- You don't have permission to access /nagios/ on this server
- SQL Server replication requires the actual server name to make a connection to the server.错误解决
- VIEW SERVER STATE permission was denied on object 'server', database 'master'
- 前端学习 -- Html&Css -- ie6 png 背景问题
- leetcode每日一题【399. 除法求值】==》并查集&模板
- 用户 'sa' 登录失败。原因: 该帐户被禁用。 (Microsoft SQL Server,错误: 18470)
- OLE DB provider "SQLNCLI11" for linked server "dbLink01" was unable to begin a distributed transac
- SQL Server 2008 R2用户'sa'登录失败(错误18456)
- ASP.NET Core静态文件中间件[5]: DirectoryBrowserMiddleware & DefaultFilesMiddleware
- 高并发&高可用系统的常见应对策略 秒杀等-(阿里)
- SQL SERVER服务器链接连接(即sql server的跨库连接)
- 华为OD机试 - 探索地块建立(Java & JS & Python)
- httpd: Could not reliably determine the server's fully qualified domain name
- 量子遗传算法(Python&Matlab实现)
- 李航老师《统计学习方法(第二版)》课件 & 算法代码全公开了!
- eclipse tomcat add时提示The Tomcat server configuration at ServersTomcat v6.0 Server at localhost-
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket
- bootstrap jQuery Ztree异步载入数据,check选择&可加入、改动、删除节点
- Could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config.
- 0402-服务注册与发现-Eureka Server使用、将服务注册到Eureka server上
- 解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- openwrt教程 第一章 物联网&openwrt开发概述
- Harmony OS — RadioButton & RadioContainer单选按钮&单选按钮组