返回顶部

收藏

把本地的SSH密钥移动到远程用户

更多
#!/bin/bash
# sends your local dev machines keys to the production machine for easy deployment + ssh

if [[ ! -e ~/.ssh/id_rsa.pub ]]; then
    echo "Local keys do not exist, creating them..."
    ssh-keygen -t rsa
fi

echo "username"
read username
echo "domain"
read domain

if [[ ! -e ~/.ssh/id_rsa.pub ]]; then
    echo "You do not have a SSH key generated locally"
    exit 1
fi

scp ~/.ssh/id_rsa.pub "$username"@"$domain":~/tmp_key
ssh "$username"@"$domain" 'if [[ ! -e ~/.ssh/ ]]; then mkdir -m 700 ~/.ssh; fi; if [[ ! -e ~/.ssh/authorized_keys ]]; then touch ~/.ssh/authorized_keys; fi; chmod 600 ~/.ssh/authorized_keys; cat ~/tmp_key >> ~/.ssh/authorized_keys; rm ~/tmp_key'

exit 0

标签:bash,shell

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. 周亮 发表 2011-07-22 06:47:59 用Bash一行一行的读取文件
  2. Chen Zhidong 发表 2010-09-26 14:27:58 Bash脚本编程中的操作符简述
  3. hongjiang 发表 2015-01-18 17:10:24 bash的陷阱(1): 逻辑或碰到local修饰符的情况
  4. wwek 发表 2014-03-24 03:01:35 Linux Bash Shell 寻找PHP(网站)挂马,后门
  5. hongjiang 发表 2015-01-15 09:11:07 vpn脚本的改进
  6. techug 发表 2016-08-03 16:44:22 Zsh Shell编程指导
  7. techug 发表 2016-09-16 04:08:17 编写可靠shell脚本的八个建议
  8. hongjiang 发表 2016-11-01 21:06:19 作业控制与前台进程组
  9. Apple 发表 2014-09-26 08:08:41 Linux Bash Shell 9.25严重漏洞紧急修复方法
  10. Scott Hanselman 发表 2017-12-03 01:42:10 Azure Cloud Shell - your own bash shell and contai
  11. igi 发表 2011-01-14 06:27:12 Bash引号的那点事
  12. bear 发表 2013-03-22 08:31:56 修改shell终端提示信息

发表评论