免密码登陆
对于大部分程序员来说,ssh的使用频率非常高,每次登陆都输入密码非常繁琐,使用下面的方法可以免密码登陆:
1
2
3
4
5
|
## 1. generate key. if you already have one skip to step 2.
ssh-keygen -t ed25519
## 2. copy public key to remote server
ssh-copy-id user@remote-server
|
## 1. generate key. if you already have one skip to step 2.
ssh-keygen -t ed25519
## 2. copy public key to remote server
ssh-copy-id user@remote-server
上面的user用真实的remote-server上的用户名替代,remote-server为远端服务器IP地址
这样就可以直接登陆到远程服务器了。
起个别名更方便
如果觉得每次都需要用户名和IP地址很麻烦,也可以通过下面的方法,给每个服务器创建一个别名,里面包含服务器的IP地址和用户名信息:
Host s1
User ticktech
HostName 10.1.2.3
Port 22
Host s1
User ticktech
HostName 10.1.2.3
Port 22
将上面的内容放到$HOME/.ssh/config
中,注意替换相关内容
- s1: 是远端服务器的别名,看自己喜好
- ticktech:替换为远端服务器的用户名
- 10.1.2.3:替换为远端服务器的IP地址
然后就可以执行: ssh s1
来测试效果了。
去掉烦人的新服务器提示信息
在每次访问要一个新的服务器的时候,都会有如下的提示信息,需要输入yes
才可以继续:
1
2
3
4
5
|
ssh termux
The authenticity of host '[192.168.1.100]:8022 ([192.168.1.100]:8022)' can't be established.
ED25519 key fingerprint is SHA256:vMfrBwvRexoYUHwriIynYQhVpAN5w7jhFzjNMZk9l7s.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
|
ssh termux
The authenticity of host '[192.168.1.100]:8022 ([192.168.1.100]:8022)' can't be established.
ED25519 key fingerprint is SHA256:vMfrBwvRexoYUHwriIynYQhVpAN5w7jhFzjNMZk9l7s.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
这个当然也可以去掉,只需要在/etc/ssh/ssh_config
中如下配置即可:
Host *
StrictHostKeyChecking no
Host *
StrictHostKeyChecking no