ssh

最初是在找mac上的ssh软件,但看到一个用iterm和ssh config的设置

常规配置

正常设置

1
2
3
4
5
6
7
8
9
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 root@183.232.159.7

可能会遇到设置了也没用的情况,得检查目标机器的sshd config是否开启密钥登录:

1.登录目标机器

2.vim /etc/ssh/sshd_config

3.修改配置

PasswordAuthentication yes

RSAAuthentication yes

PubkeyAuthentication yes

4.重启sshd服务

systemctl restart sshd

跳板机设置

1
2
3
4
5
6
7
8
9
10
11
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
1
2
%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
posted @   王鹏鑫  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示