最初是在找mac上的ssh软件,但看到一个用iterm和ssh config的设置
常规配置
正常设置
Host * Port 22 ServerAliveInterval 120 Host target HostName $HOST Port $PORT IdentityFile ~/.ssh/id_rsa User $USER
$分别指代自己对应的端口号、用户名等等
免密登录
事例:
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 11040 [email protected]
可能会遇到设置了也没用的情况,得检查目标机器的sshd config是否开启密钥登录:
1.登录目标机器
2.vim /etc/ssh/sshd_config
3.修改配置
PasswordAuthentication
yes
RSAAuthentication yes
PubkeyAuthentication yes
4.重启sshd服务
systemctl restart sshd
跳板机设置
Host gateway HostName $GATEWAY_HOST Port $GATEWAY_PORT IdentityFile ~/.ssh/id_rsa User $GATEWAY_USER Host target HostName $TARGET_HOST User $TARGET_USER IdentityFile ~/.ssh/id_rsa ProxyCommand ssh gateway nc %h %p 2> /dev/null # 或者 ProxyCommand ssh gateway -W %h:%p
%h 表示 hostname %p 表示 port
ssh target 'mkdir -p .ssh && cat > .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
ssh target
scp some_file target:/home/user
rsync -avP * target:/home/user/some_dir
标签:sshd,target,rsa,Host,ssh,id
From: https://www.cnblogs.com/twh233/p/18260270