如何使用 shell 配置 rc.local?

如何使用 shell 配置 rc.local?

我需要为 Ubuntu 服务器 16.04 设置反向 ssh 连接。我搜索了用变量写入文件的不同方法,但没有找到适合我的情况的方法:(

要执行的命令: autossh -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/myUser/.ssh/nopwd -R ${PORT_NUMBER}:localhost:22 [email protected] &

我使用这个脚本;

#!/bin/bash `
KEY_PATH=/home/myUser/.ssh/nopwd echo "generating your key..."
ssh-keygen -b 2048 -t rsa -f $KEY_PATH  -N ""
echo "the key is saved under: $KEY_PATH "
ssh-copy-id -i /home/myUser/.ssh/nopwd.pub [email protected]
echo "key sent..."
echo "enter a free port..."
read PORT_NUMBER
sed -i -e '$i \autossh -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/myUser/.ssh/nopwd -R $PORT_NUMBER:localhost:22 [email protected] &' /etc/rc.local

这个想法是使用此脚本设置 rc.local 命令的端口号。

欢迎所有建议,因为我对 linux 和 bash 很陌生。

相关内容