ssh-scp

  • [ ssh 基础操作 ]
  •   local$ ssh user@remote -p port
      // -p 指定端口,默认22, remove是远程机的ip
    

  • [ 免密登陆 ]
  •   local$ ssh-keygen
      // 本条命令会生成一对秘钥
      local$ ssh-copy-id user@remote -p port
      // 这条命令会将公钥上传到远程机,输入远程机登陆密码即可完成
      // 完成后登陆远程机就不用再输入密码了
    

  • [ 配置别名 ]
    • 将以下内容追加到 ~/.ssh/config 中即可完成配置
      Host web
        Hostname remote // 远程机的ip地址
        pUser user // 远程机用户的用户名
        Port port // 默认22,可以省略不写
        
    
    • 配置好秘钥和别名后,登陆就变得容易很多了
      local$ ssh web
    

  • [ scp 传输文件 ]
    • 在配置好别名和秘钥后,操作 scp 会方便很多
      local$ scp dir/file web:dir/
      // 将本地目录 dir 中的 file 传输到远程机 web 的 dir 目录下
      local$ scp web:dir/file dir/file
      // 将远程机 web的 dir 目录中的 file 传输到本地目录 的 dir 目录下
    
    posted @ 2024-03-15 10:31  anch  阅读(22)  评论(0)    收藏  举报