调试linux嵌入式设备,往往需要在编译服务器上编译代码,然后将编译好的固件拷贝到本地,再将固件烧录到单板,整个过程繁琐费事,这里总结如何在windows上通过一键式脚本完成编译和文件拷贝;
1、在Linux上创建账号
如下xxx表示创建的新账号
useradd -d /home/xxx -m xxx
passwd xxx
chown -R lilin /home/xxx
chgrp -R lilin /home/xxx
使用xxx账号登入后执行如下命令:
ssh-keygen -t rsa
2、在Windows上安装git命令行工具
自行百度安装
3、在Windows上远程执行Linux上命令
打开git bash命令行终端
执行ssh-keygen -t rsa创建公钥,一路回车完成
执行如下命令,完成公钥拷贝:
USER=xxx
HOST_IP=xx.xx.xx.xx
cat ~/.ssh/id_rsa.pub | ssh U S E R @ {USER}@ USER@{HOST_IP} ‘cat >> ~/.ssh/authorized_keys’
拷贝完成后即可执行命令,例如:
ssh -p 22 %USER%@%HOST_IP% “pwd”
4、拷贝Linux上文件到本地
USER=xxx
HOST_IP=xx.xx.xx.xx
scp -p ${HOST_PORT} U S E R @ {USER}@ USER@{HOST_IP}{IMG_NAME} .
USER=xxx
PASSWD=xxx
HOST_PORT=22
HOST_IP=xxx
IMG_NAME=xxx
TARGET=$1
[ -z "$TARGET" ] && {
echo "+--------------------------------------------------------+"
echo "| Welcome to Project Build Menu |"
echo "+--------------------------------------------------------+"
echo "| 0. copy pub key |"
echo "| 1. excute cmd |"
echo "| 2. copy img |"
echo "+--------------------------------------------------------+"
echo -n "==> "
read action
case ${action} in
0)
cat ~/.ssh/id_rsa.pub | ssh ${USER}@${HOST_IP} 'cat >> ~/.ssh/authorized_keys'
;;
1)
ssh -p ${HOST_PORT} ${USER}@${HOST_IP} "cd ${PROJECT_BASE};./my_compile.sh"
;;
2)
scp -p ${HOST_PORT} ${USER}@${HOST_IP}:${IMG_NAME} .
;;
esac
}
ssh免密码远程执行sudo命令
https://blog.csdn.net/kefeng_chen/article/details/49935157