2016年3月21日星期一

ubuntu中配置不用每次都ssh-add输入passphrase

先安装expect:
apt-get install expect

我用的是root用户,/root/.ssh/xychen是你的key文件,chmod 600 /root/.ssh/xychen

vim /root/ssh-add.sh,内容如下:
#!/usr/bin/expect
spawn ssh-agent zsh
spawn ssh-add /root/.ssh/xychen
expect "Enter passphrase for /root/.ssh/xychen:"
send "your_passphrase\r"
interact

修改~/.bashrc文件,我使用的是zsh,所以修改~/.zshrc文件,在最后加上:
eval `ssh-agent`
/root/ssh-add.sh

没有评论:

发表评论