debain运行脚本报错,把脚本中的命令单独执行就没有问题
今天拿一台机器dd了一个debain11,想要用一键脚本设置秘钥登录,因为国内鸡连不上github,几把脚本内容复制下来粘贴到记事本当中上传到小鸡上,并修改后缀名为*.sh<br> 然后运行该脚本总是报错,但是吧脚本内容单独拿出来执行却又没有问题,请问大佬指教一下是什么原因?用的是这个一键脚本:https://github.com/KiritoMiao/SSHKEY_Installer/<br> <br> 以下是脚本内容:<br>
<div class="blockcode">
<div id="code_Zru">
<ol>
<li>#/bin/sh<br> </li>
<li>apt-get update -y<br> </li>
<li>apt-get install curl -y<br> </li>
<li>yum clean all<br> </li>
<li>yum make cache<br> </li>
<li>yum install curl -y<br> </li>
<li>echo '============================<br> </li>
<li> SSH Key Installer<br> </li>
<li> V1.0 Alpha<br> </li>
<li> Author:Kirito<br> </li>
<li>============================'<br> </li>
<li>cd ~<br> </li>
<li>mkdir .ssh<br> </li>
<li>cd .ssh<br> </li>
<li>curl https://github.com/$1.keys > authorized_keys<br> </li>
<li>chmod 700 authorized_keys<br> </li>
<li>cd ../<br> </li>
<li>chmod 600 .ssh<br> </li>
<li>cd /etc/ssh/<br> </li>
<li><br> </li>
<li>sed -i "/PasswordAuthentication no/c PasswordAuthentication no" sshd_config<br> </li>
<li>sed -i "/RSAAuthentication no/c RSAAuthentication yes" sshd_config<br> </li>
<li>sed -i "/PubkeyAuthentication no/c PubkeyAuthentication yes" sshd_config<br> </li>
<li>sed -i "/PasswordAuthentication yes/c PasswordAuthentication no" sshd_config<br> </li>
<li>sed -i "/RSAAuthentication yes/c RSAAuthentication yes" sshd_config<br> </li>
<li>sed -i "/PubkeyAuthentication yes/c PubkeyAuthentication yes" sshd_config<br> </li>
<li>service sshd restart<br> </li>
<li>service ssh restart<br> </li>
<li>systemctl restart sshd<br> </li>
<li>systemctl restart ssh<br> </li>
<li>cd ~<br> </li>
<li>rm -rf key.sh</li>
</ol>
</div><em onclick="copycode($('code_Zru'));">复制代码</em>
</div><br> <br> ============================<br> <br> <br> 运行报错内容:<br>
<div class="blockcode">
<div id="code_VFf">
<ol>
<li>root@debian:~# bash key.sh<br> </li>
<li>E: Command line option '<br> </li>
<li> ' [from -y<br> </li>
<li> ] is not understood in combination with the other options.<br> </li>
<li>E: Command line option '<br> </li>
<li> ' [from -y<br> </li>
<li> ] is not understood in combination with the other options.<br> </li>
<li>key.sh: line 4: yum: command not found<br> </li>
<li>key.sh: line 5: yum: command not found<br> </li>
<li>key.sh: line 6: yum: command not found<br> </li>
<li>============================<br> </li>
<li> SSH Key Installer<br> </li>
<li> V1.0 Alpha<br> </li>
<li> Author:Kirito<br> </li>
<li>============================<br> </li>
<li>key.sh: line 12: cd: $'~\r': No such file or directory<br> </li>
<li>mkdir: cannot create directory ‘.ssh\r’: File exists<br> </li>
<li> % Total % Received % Xferd Average Speed Time Time Time Current<br> </li>
<li> Dload Upload Total Spent Left Speed<br> </li>
<li>100 9 100 9 0 0 11 0 --:--:-- --:--:-- --:--:-- 11<br> </li>
<li>key.sh: line 17: cd: $'../\r': No such file or directory<br> </li>
<li>chmod: cannot access '.ssh'$'\r': No such file or directory<br> </li>
<li>key.sh: line 19: cd: $'/etc/ssh/\r': No such file or directory<br> </li>
<li>key.sh: line 20: $'\r': command not found<br> </li>
<li>: No such file or directory<br> </li>
<li>: No such file or directory<br> </li>
<li>: No such file or directory<br> </li>
<li>: No such file or directory<br> </li>
<li>: No such file or directory<br> </li>
<li>: No such file or directory<br> </li>
<li>sshd: unrecognized service<br> </li>
<li>Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}.<br> </li>
<li>Invalid unit name "sshd<br> </li>
<li>" escaped as "sshd\x0d" (maybe you should use systemd-escape?).<br> </li>
<li>Failed to restart sshd\x0d.service: Unit sshd\x0d.service not found.<br> </li>
<li>Invalid unit name "ssh<br> </li>
<li>" escaped as "ssh\x0d" (maybe you should use systemd-escape?).<br> </li>
<li>Failed to restart ssh\x0d.service: Unit ssh\x0d.service not found.<br> </li>
<li>key.sh: line 31: cd: $'~\r': No such file or directory</li>
</ol>
</div><em onclick="copycode($('code_VFf'));">复制代码</em>
</div><br> <br> 虽然自己的目标已经达到,单独复制出脚本内容来执行的,但是运行脚本为什么会报错还不知道原因,请大佬指点一下。感谢。
收藏(0)
分享
相关标签:
注意:本文归作者所有,未经作者允许,不得转载
-
2022年11月15日 07:12
用 vscode 把 CRLF 转成 LF
0
0