Linux ssh命令加入密码直接登陆
时间: 2024-09-24 11:14:08 浏览: 168
Linux中的SSH(Secure Shell)通常需要输入用户名和密码进行身份验证,但这并不意味着每次登录都需要手动输入密码。你可以通过配置`~/.ssh/config`文件将默认密码信息存储起来,以便于更方便地进行SSH连接。
要在`.ssh/config`文件中添加密码登录的信息,可以创建一个新的或打开已存在的配置文件,然后添加以下内容:
```bash
Host <hostname>
HostName <主机地址>
User <用户名>
PasswordAuthentication yes
# 如果需要加密保存密码,也可以使用下面这行(注释掉PasswordAuthentication行)
# IdentityFile ~/.ssh/id_rsa
```
在这里,`<hostname>`是你想要连接的服务器的名称或IP地址,`<用户名>`是你的登录账户名。`PasswordAuthentication yes`表示启用密码认证。
如果不想每次都显示密码输入,可以选择使用SSH密钥对进行无密码登录,这时你需要生成一个私钥并将其放置在远程服务器的`~/.ssh/authorized_keys`文件中,本地则不需要存储明文密码。只需将`PasswordAuthentication`改为`PubkeyAuthentication yes`,并指定公钥路径(如`IdentityFile ~/.ssh/id_rsa.pub`)。
记得替换上述示例中的占位符为实际值,然后保存配置文件即可。下次使用`ssh <hostname>`命令时,系统会自动读取配置并按照设定的方式进行登录。
阅读全文
相关推荐
















