如何SSH无密码登录

Aru*_*ony 5 ssh ksh ssh-keys

在没有用户交互的情况下在脚本中使用sftp(非交互式).例如,登录匿名ftp服务器而不必手动.

E.G*_*.G. 14

在你的电脑

cd ~/.ssh
ssh-keygen -t dsa
Run Code Online (Sandbox Code Playgroud)

在每个提示符下按Enter键

Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/id_dsa.pub.
The key fingerprint is:
ad:98:43:13:c9:ea:66:8e:d0:d9:66:59:d8:3a:f7:29
The key's randomart image is:
+--[ DSA 1024]----+
|                 |
|     . .         |
|      +          |
|     + . .       |
|    o = S .      |
| . + = + .       |
|. o @ = .        |
| . B oEo .       |
|  . .  .o        |
+-----------------+
Run Code Online (Sandbox Code Playgroud)

您将获得2个文件,id_dsaid_dsa.pub使用scp或其他实用程序将文件复制到您的服务器

scp ~/.ssh/id_dsa.pub user@host:~/.ssh/
Run Code Online (Sandbox Code Playgroud)

在您的服务器上

将新密钥添加到文件〜/ .ssh/authorized_keys.

cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

最后改变访问模式;

chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
Run Code Online (Sandbox Code Playgroud)

验证〜的访问模式是否正确

ls -ld ~
Run Code Online (Sandbox Code Playgroud)

如果没有,你可以使用

chmod 700 ~
Run Code Online (Sandbox Code Playgroud)

纠正您的家庭访问.

注销并再次登录

  • 去年,OpenSSH [已弃用的 DSA 密钥](http://security.stackexchange.com/questions/112802/why-openssh-deprecated-dsa-keys)。使用 RSA 密钥,除非您有特定原因不这样做。RSA 密钥文件名通常为 *id_rsa* 和 *id_rsa.pub*。 (2认同)

小智 10

键入以下命令

  1. ssh-keygen

    按Enter键直到出现提示

  2. ssh-copy-id -i root@ip_address

    (它会一次询问主机系统的密码)

  3. ssh root@ip_address

    现在您应该可以在没有任何密码的情况下登录