用户工具

站点工具


linux:scp
  • 免密登录
  //host-A
  ssh-keygen
  scp id_rsa.pub user@ip:~/.ssh/  #需要密码
  //host-B
  cp id_rsa.pub ~/.ssh/authorized_keys
  chmod 700 ~/.ssh
  chmod 600 ~/.ssh/authorized_keys
  //host-A
  ssh user@ip  #免密登录
  • 传输文件
  scp target/bpmdemo.jar root@backup:/soft/share/bpmdemo/target
  发送:scp send-file root@host:path,获取:scp root@host:path save-path
  • 同步目录
  sh rsync.sh put backup /soft/gitdata/bpmdemo/target soft/share/bpmdemo
limit=100000

if [ $# != 4 ]; then
echo "rsync.sh get|put host dir1 dir2"
elif [ $1 == "get" ]; then
echo "rsync get $2 $3 $4"
rsync -ztrulp --progress --bwlimit=$limit --password-file=/etc/rsync.secret rsyncuser@$2::$3 $4 --log-file=/var/log/rsync.log

elif [ $1 == "put" ]; then
echo "rsync put $2 $3 $4"
rsync -ztrulp --progress --bwlimit=$limit --password-file=/etc/rsync.secret $3 rsyncuser@$2::$4 --log-file=/var/log/rsync.log

else
echo "rsync.sh get|put host dir1 dir2"
fi
  • 远程执行
  ssh root@backup "cd /soft/share/bpmdemo; sh start.sh stop"
  • ssh-keygen,Jsch不支持OPENSSH密钥时,可以转换一下或重新生成
ssh-keygen -m PEM -t rsa
ssh-keygen -p -f ~/.ssh/id_rsa -m pem
linux/scp.txt · 最后更改: 2021/04/27 11:51 由 admin