SSH 的使用

服务球端安装 ssh

  1. 测试服务器是否安装了 ssh

    1
    2
    3
    ps -e | grep ssh
    # ssh-agent exist -> ssh client okay
    # sshd exist -> ssh server okay
    
  2. 安装 ssh

    1
    2
    3
    4
    5
    # ssh-client
    sudo apt-get install openssh-client
    
    # ssh-server
    sudo apt-get install openssh-server
    
  3. 更换 ssh 服务默认端口

    • 使用 vim 打开配置文件 /etc/ssh/sshd_config,搜索 port 更改端口号即可。
    • sudo /etc/init.d/ssh restart

用自己想用的用户名登陆

  1. ~/.ssh中创建一个文件config
  2. 在里面输入

    1
    2
    3
    4
    5
    Host gpu_server_host
      SetEnv TERM=xterm-256color
        HostName server_ip
        Port 22
        User username
    
  3. 重启终端即可

SCP

1
2
scp -r /local/path username@server_ip:/server/path
scp -r username@server_ip:/server/path /local/path

18. scp 跨机远程拷贝 - Linux Tools Quick Tutorial

免密登陆

  1. 在本机生成公钥、私钥对

    1
    2
    ssh-keygen
    # 会生成 id_rsa.pub 到 ~/.ssh 里面
    
  2. id_rsa.pub 传到服务器端

    1
    scp id_rsa.pub your_username@ip:~/home/your_username
    
  3. 服务器端创建 authorized_keys

    1
    2
    touch ~/.ssh/authorized_keys
    sudo chmod 600 ~/.ssh/authorized_keys
    
  4. 追加公钥到 authorized_keys 文件中

    1
    cat id_rsa.pub >> ~/.ssh/authorized_keys
    

禁止密码口令登录

通常在配置完服务器以后默认是允许用户名密码登录的,但是为了安全着想,我们应该只允许使用密钥登录,具体的办法为修改 /etc/ssh/sshd_config 文件。修改其中 PasswordAuthenticationno 即可。

  • 本文作者: Author:DeamoV
  • Github:https://github.com/Duan-JM
  • Email:vincent.duan95@outlook.com
  • 本文链接: Artical: SSH 的使用
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!
  • 版权声明: 原创文章如转载,请注明出处