ssh $user@$target -p 1220 'mkdir -p .ssh && cat > .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
user
是登陸名,target
是目標機器.第一次輸好密碼,後面就不用輸了.bash
在~/.ssh/config中配置好別名ssh
Host gateway HostName gateway url Port 1220 IdentityFile ~/.ssh/id_rsa User xxx Host target HostName target url User xxx IdentityFile ~/.ssh/id_rsa ProxyCommand ssh gateway nc %h %p 2> /dev/null
執行命令url
ssh target 'mkdir -p .ssh && cat > .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
和上面同樣,也只須要第一次輸入密碼code