Common settings for SSH connections on Mac - extending the connection timeout, aliasing the ‘ssh username@IP address’ command, etc.

Set the connection timeout and increase the session time of the connection

MacThe terminal of can be used directlySSH命令连接远程服务器, but by default the connection maintains the session for a short time and requires constant re-logging, which is troublesome; you can add SSH

# 1、打开Mac的SSH配置目录
cd /etc/ssh/
# 2、修改SSH客户端连接配置文件ssh_config(sshd_config是服务端配置文件,这里用不上)
sudo vim /etc/ssh/ssh_config
# 3、在文件最后追加两条配置:
# 3.1、服务器发出请求后客户端未响应次数达到该值就自动断开
# 这里设置3次
ServerAliveCountMax 3
# 3.2、配置服务器端向客户端请求消息的时间间隔
# 默认是0(不发送),这里设置每60秒向服务器发送一次,这样就可以保持连接
ServerAliveInterval 60

Alias ​​the ‘ssh username@IP address’ command

MacSSH命令连接远程服务器When using under ssh 用户名@IP地址 every time; you can set an alias for this command, and you can quickly connect based on the alias in the future. The relevant configuration is as follows:, you need to enter

# 1、查看当前使用的shell是哪个
# 1.1、如果是bash,则在当前用户的家目录创建.bash_profile文件(先查看如果没有再创建)
# 1.2、如果使用的是zsh,则在当前用户的家目录创建.zprofile文件(先查看如果没有再创建)
echo $SHELL
# 2、进入用户家目录下
cd ~
# 3、在最后追加如下命令:
# vim .bash_profile
alias aliyun_dev='ssh 用户名@IP地址'
# 4、刷新配置文件
source .bash_profile	
# 以后只要输入命令:aliyun_dev,就可以连接上远程服务器了
# 5、测试一下
aliyun_dev

is as shown below; through the above configuration, you can use aliyun_dev instead of 'ssh 用户名@IP地址' command in the future
Insert image description here

おすすめ

転載: blog.csdn.net/weixin_43859011/article/details/132090828