服务球端安装 ssh
-
测试服务器是否安装了 ssh
1
2
3ps -e | grep ssh # ssh-agent exist -> ssh client okay # sshd exist -> ssh server okay -
安装 ssh
1
2
3
4
5# ssh-client sudo apt-get install openssh-client # ssh-server sudo apt-get install openssh-server -
更换 ssh 服务默认端口
- 使用
vim打开配置文件/etc/ssh/sshd_config,搜索port更改端口号即可。 sudo /etc/init.d/ssh restart
- 使用
用自己想用的用户名登陆
- 在
~/.ssh中创建一个文件config -
在里面输入
1
2
3
4
5Host gpu_server_host SetEnv TERM=xterm-256color HostName server_ip Port 22 User username - 重启终端即可
SCP
1 | |
18. scp 跨机远程拷贝 - Linux Tools Quick Tutorial
免密登陆
-
在本机生成公钥、私钥对
1
2ssh-keygen # 会生成 id_rsa.pub 到 ~/.ssh 里面 -
将
id_rsa.pub传到服务器端1
scp id_rsa.pub your_username@ip:~/home/your_username -
服务器端创建
authorized_keys1
2touch ~/.ssh/authorized_keys sudo chmod 600 ~/.ssh/authorized_keys -
追加公钥到
authorized_keys文件中1
cat id_rsa.pub >> ~/.ssh/authorized_keys
禁止密码口令登录
通常在配置完服务器以后默认是允许用户名密码登录的,但是为了安全着想,我们应该只允许使用密钥登录,具体的办法为修改 /etc/ssh/sshd_config 文件。修改其中 PasswordAuthentication 为 no 即可。