Appearance
R 语言 IDE:Positron 对接服务器
视频教程
简介
- SSH 远程连接配置的详细步骤
- 在 Positron 中运行 R 项目的方法
- 文件同步方式和最佳实践
- 远程调试技巧和注意事项
免密登录-windows PS
逐行执行即可
bash
# -----------------------------
# 1. 获取可用公钥
# -----------------------------
# 优先查找默认 ed25519
$default_pub = "$env:USERPROFILE\.ssh\id_ed25519.pub"
# 查找带时间戳或自定义后缀的 ed25519 公钥
$latest_custom = Get-ChildItem "$env:USERPROFILE\.ssh\id_ed25519_*.pub" -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if (Test-Path $default_pub) {
$latest = Get-Item $default_pub
Write-Host "使用默认公钥:$($latest.Name)"
} elseif ($latest_custom) {
$latest = $latest_custom
Write-Host "使用最新自定义公钥:$($latest.Name)"
} else {
# 如果都没有,生成一把新的
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$path = "$env:USERPROFILE\.ssh\id_ed25519_$timestamp"
ssh-keygen -t ed25519 -f $path -C "ysx@$timestamp"
$latest = Get-Item "$path.pub"
Write-Host "生成新公钥:$($latest.Name)"
}
# -----------------------------
# 2. 推送到远程 authorized_keys(不重复追加)
# -----------------------------
# 需要修改 用户名 ip 端口
$remote_user = "账号" # 替换为实际用户名
$remote_host = "yun.biocloudai.cn"
$remote_port = 端口如6622 # 替换为实际端口
$pub_content = Get-Content $latest.FullName -Raw
ssh -p $remote_port $remote_user@$remote_host "
mkdir -p ~/.ssh;
grep -Fxq '$pub_content' ~/.ssh/authorized_keys 2>/dev/null || echo '$pub_content' >> ~/.ssh/authorized_keys;
chmod 700 ~/.ssh;
chmod 600 ~/.ssh/authorized_keys
"
Write-Host "公钥已推送到 $remote_user@$remote_host"
#ssh -p $remote_port $remote_user@$remote_host
$private_key = $latest.FullName -replace '\.pub$', ''
ssh -i $private_key -p $remote_port "$remote_user@$remote_host"免密登录-macos
逐行执行即可
bash
#!/bin/bash
# -----------------------------
# 1️⃣ 获取可用公钥
# -----------------------------
default_pub="$HOME/.ssh/id_ed25519.pub"
# 查找自定义/时间戳公钥
latest_custom=$(ls -t ~/.ssh/id_ed25519_*.pub 2>/dev/null | head -n 1)
if [ -f "$default_pub" ]; then
latest_key="$default_pub"
echo "使用默认公钥:$latest_key"
elif [ -n "$latest_custom" ]; then
latest_key="$latest_custom"
echo "使用最新自定义公钥:$latest_key"
else
# 如果都没有,生成新公钥
timestamp=$(date +%Y%m%d_%H%M%S)
latest_key="$HOME/.ssh/id_ed25519_$timestamp.pub"
ssh-keygen -t ed25519 -f "${latest_key%.pub}" -C "rainsc@$timestamp"
echo "生成新公钥:$latest_key"
fi
# -----------------------------
# 2️⃣ 推送到远程 authorized_keys(不重复追加)
# -----------------------------
# 需要修改 用户名 ip 端口
remote_user="账号" # 替换为实际用户名
remote_host="yun.biocloudai.cn"
remote_port=6622 # 替换为实际端口
pub_content=$(cat "$latest_key")
ssh -p "$remote_port" "$remote_user@$remote_host" "
mkdir -p ~/.ssh;
grep -Fxq \"$pub_content\" ~/.ssh/authorized_keys 2>/dev/null || echo \"$pub_content\" >> ~/.ssh/authorized_keys;
chmod 700 ~/.ssh;
chmod 600 ~/.ssh/authorized_keys
"
echo "公钥已推送到 $remote_user@$remote_host"
# 使用对应私钥登录
ssh -i "${latest_key%.pub}" -p "$remote_port" "$remote_user@$remote_host"相关命令
bash
# SSH 连接命令示例
ssh username@server_ip -p 22
# R 命令示例
library(package_name)
setwd("/path/to/project")常见问题
- 连接超时:检查网络连接和服务器配置
- 文件同步失败:确认 SFTP 配置正确
- 权限问题:确保用户有相应的读写权限
- 性能优化:关闭不必要的文件监控功能
