linux – 使用Shell脚本提供密码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux – 使用Shell脚本提供密码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1683字,纯文字阅读大概需要3分钟。
内容图文
![linux – 使用Shell脚本提供密码](/upload/InfoBanner/zyjiaocheng/951/daf7cc4b41de4606af0155d3807418f4.jpg)
我设置了我的客户&用于无密码登录的服务器.
像无密码登录一样,将服务器的RSA密钥复制到所有客户端的/root/.ssh/id-rsa.pub.但是,我已经手动完成了.我喜欢使用shell脚本自动执行此过程,并通过脚本为机器提供密码.
如果此问题得到解决,那么我还想使用rsync自动将推送项目发送到所有服务器.
在这方面,任何人都可以帮助我.
谢谢
解决方法:
这个脚本来自Debian(和衍生产品)机器,用于分发密钥.它叫做ssh-copy-id.你会这样使用它:
ssh-copy-id [-i identity_file] [user@]machine
然后你输入密码就可以复制了.你只会这样做一次,然后像往常一样使用ssh上的rsync.
#!/bin/sh
# Shell script to install your identity.pub on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
ID_FILE="${HOME}/.ssh/identity.pub"
if [ "-i" = "$1" ]; then
shift
# check if we have 2 parameters left, if so the first is the new ID file
if [ -n "$2" ]; then
if expr "$1" : ".*\.pub" ; then
ID_FILE="$1"
else
ID_FILE="$1.pub"
fi
shift # and this should leave $1 as the target name
fi
else
if [ x$SSH_AUTH_SOCK != x ] ; then
GET_ID="$GET_ID ssh-add -L"
fi
fi
if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
GET_ID="cat ${ID_FILE}"
fi
if [ -z "`eval $GET_ID`" ]; then
echo "$0: ERROR: No identities found" >&2
exit 1
fi
if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
exit 1
fi
{ eval "$GET_ID" ; } | ssh $1 "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1
cat <<EOF
Now try logging into the machine, with "ssh '$1'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
EOF
内容总结
以上是互联网集市为您收集整理的linux – 使用Shell脚本提供密码全部内容,希望文章能够帮你解决linux – 使用Shell脚本提供密码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。