Mac程序员-ssh免密码登陆

2024/04/05 | 字数565 | 阅读2分钟


免密码登陆

对于大部分程序员来说,ssh的使用频率非常高,每次登陆都输入密码非常繁琐,使用下面的方法可以免密码登陆:

bash
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

上面的user用真实的remote-server上的用户名替代,remote-server为远端服务器IP地址

这样就可以直接登陆到远程服务器了。

起个别名更方便

如果觉得每次都需要用户名和IP地址很麻烦,也可以通过下面的方法,给每个服务器创建一个别名,里面包含服务器的IP地址和用户名信息:

conf
Host s1
    User ticktech
    HostName 10.1.2.3
    Port 22

将上面的内容放到$HOME/.ssh/config中,注意替换相关内容

然后就可以执行: ssh s1来测试效果了。

去掉烦人的新服务器提示信息

在每次访问要一个新的服务器的时候,都会有如下的提示信息,需要输入yes才可以继续:

bash
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])?

这个当然也可以去掉,只需要在/etc/ssh/ssh_config中如下配置即可:

conf
Host * 
    StrictHostKeyChecking no
上一篇:Mac程序员-sudo免密码 下一篇:Mac程序员-禁用.DS_Store文件

【文章不错,鼓励一下】