当前位置:首页 » 操作系统 » 免密码sshlinux

免密码sshlinux

发布时间: 2022-10-04 21:28:48

linux下怎样设置ssh无密码登录

首先你要有一个无密码的用户。
修改ssh配置文件,步骤如下:
1)
修改 /etc/ssh/sshd_config
文件中 PermitEmptyPasswords
这个参数为yes(即允许空密码的用户登录,默认是no)
2)
重启
ssh服务,service
ssh
restart
3)
重新登录ssh,即可无密码登录。

② linux下怎样设置ssh无密码登录

ssh-keygen 生成密钥
公钥拷贝到对方机器,其实应该是追加,别冲了原文件。
scp ~/.ssh/id_rsa.pub 192.168.xxx.xxx:~/.ssh/authorized_keys
有了别人的公钥,就可以登录了。第一次要指纹确定一次。

③ linux下怎样设置ssh无密码登录

1) 在本地主机生成密钥对
ssh-keygen -t rsa
这个命令生成一个密钥对:id_rsa(私钥文件)和id_rsa.pub(公钥文件)。默认被保存在~/.ssh/目录下。
2) 将公钥添加到远程主机的 authorized_keys 文件中
将文件上传到远程主机中
scp ~/.ssh/id_rsa.pub [email protected]:/root/
SSH到登陆到远程主机192.168.17.113,将公钥追加到 authorized_keys 文件中
cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
或直接运行命令:
cat ~/.ssh/id_dsa.pub|ssh [email protected] 'sh -c "cat - >>~/.ssh/authorized_keys"'
3) 重启 open-ssh 服务
/etc/init.d/ssh restart
4) 本地测试
ssh [email protected]

④ linux下怎样设置ssh无密码登录

用SSL加密Key实现自动登录
需要材料:
1 被管理的SSH服务器一台。
2 管理端电脑一台。

环境:
管理服务器: ip:192.168.0.1 机器名:server
被管理服务器:ip:192.168.0.2 机器名:client

生成密钥对:
生成公钥密钥对是在管理服务器上生成的:

[root@server ~]# ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair. #提示正在生成rsa密钥对
Enter file in which to save the key (/home/usrname/.ssh/id_dsa): #询问公钥和私钥存放的位置,回车用默认位置即可
Enter passphrase (empty for no passphrase): #询问输入私钥密语,输入密语
Enter same passphrase again: #再次提示输入密语确认
Your identification has been saved in /home/usrname/.ssh/id_dsa. #提示公钥和私钥已经存放在/root/.ssh/目录下
Your public key has been saved in /home/usrname/.ssh/id_dsa.pub.
The key fingerprint is:
x6:68:xx:93:98:8x:87:95:7x:2x:4x:x9:81:xx:56:94 root@server #提示key的指纹

拷贝你的公钥到被管理的服务器上
在你的管理服务器上把你的公钥拷贝到被管理服务器上要进行自动登陆的用户目录下。

[root@server ~]# scp .ssh/id_dsa.pub [email protected]: #比如你想使用用户peter登陆,则remote_usrname请以peter代替

改名和进行权限设置
登陆被管理的服务器,进入需要远程登陆的用户目录,把公钥放到用户目录的 .ssh 这个目录下(如果目录不存在,需要创建~/.ssh目录,并把目录权限设置为700),把公钥改名为authorized_keys2,并且把它的用户权限设成600。

[peter@client ~]$ ls
id_rsa.pub
[peter@client ~]$ mkdir ~/.ssh #如果当前用户目录下没有 .ssh 目录,请先创建目录
[peter@client ~]$ chmod 700 ~/.ssh
[peter@client ~]$ mv id_rsa.pub ~/.ssh
[peter@client ~]$ cd ~/.ssh
[peter@client ~]$ cat id_rsa.pub >> authorized_keys2
[peter@client ~]$ rm -f id_rsa.pub
[peter@client ~]$ chmod 600 authorized_keys2
[peter@client ~]$ ls -l
total 4
-rw------- 1 peter peter 225 Oct 10 11:28 authorized_keys2

测试使用密钥对进行远程登陆

[root@server ~]# ssh [email protected]
Enter passphrase for key '/root/.ssh/id_rsa': #提示输入密码短语,请输入刚才设置的密码短语
Last login: Sun Oct 10 11:32:14 2010 from 192.168.0.1
[peter@client ~]$

如果你不能用正确的登录,应该重新检查一下你的authorized_keys2的权限。也可能要检查.ssh目录的权限。
使用 ssh-agent(ssh代理)自动输入密码短语
牢记你的“密码短句”,现在你可以用你的密钥而不是密码来登录你的服务器了,但是这样仍然没有省什么事,你还是要输入密钥的“密码短语”。有更简便的方法吗?答案就是采用SSH代理(ssh-agent),一个用来帮你记住“密码短语”的程序。 ssh-agent是OpenSSH中默认包括的ssh代理程序。
登陆管理服务器

[root@server ~]# ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2148; export SSH_AGENT_PID;
echo Agent pid 2148;

当你运行ssh-agent,它会打印出来它使用的 ssh 的环境和变量。要使用这些变量,有两种方法,一种是手动进行声明环境变量,另一种是运行eval命令自动声明环境变量。
方法一:手动声明环境变量

[root@server ~]# SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147; export SSH_AUTH_SOCK;
[root@server ~]# SSH_AGENT_PID=2148; export SSH_AGENT_PID;
[root@server ~]# printenv | grep SSH #检查 ssh 环境变量是否已经加入当前会话的环境变量
SSH_AGENT_PID=2148
SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147

方法二:运行eval命令自动声明环境变量

[root@server ~]# eval `ssh-agent`
Agent pid 2157
[root@server ~]# printenv | grep SSH #检查 ssh 环境变量是否已经加入当前会话的环境变量
SSH_AGENT_PID=2148
SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147

现在 ssh-agent 已经在运行了,但是 ssh-agent 里面是空白的不会有解密的专用密钥。我们要告诉它我们有私钥和这个私钥在哪儿。这就需要使用 ssh-add 命令把我们的专用密钥添加到 ssh-agent 的高速缓存中。

[root@server ~]# ssh-add ~/.ssh/id_dsa
Enter passphrase for /home/user/.ssh/id_dsa: #输入你的密码短语
Identity added: /home/user/.ssh/id_dsa (/home/user/.ssh/id_dsa)
[root@server ~]# ssh-add -l #查看 ssh代理的缓存内容
1024 72:78:5e:6b:16:fd:f2:8c:81:b1:18:e6:9f:77:6e:be /root/.ssh/id_rsa (RSA)

输入了密码短句,现在好了,你可以登录你的远程服务器而不用输入你的密码短语了,而且你的私钥是密码保护的。

⑤ linux下怎样设置ssh无密码登录

第1步:在本地主机中生成“密钥对”并将公钥传送到远程服务器中:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):直接敲击回车或设置密钥的存储路径
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 直接敲击回车或设置密钥的密码
Enter same passphrase again: 再次敲击回车或设置密钥的密码
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
40:32:48:18:e4:ac:c0:c3:c1:ba:7c:6c:3a:a8:b5:22 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|+*..o . |
|*.o + |
|o* . |
|+ . . |
|o.. S |
|.. + |
|. = |
|E+ . |
|+.o |
+-----------------+

第2步:将生成好的私钥文件传送至远程主机:
[root@linuxprobe ~]# ssh--id 192.168.10.20
The authenticity of host '192.168.10.20 (192.168.10.20)' can't be established.
ECDSA key fingerprint is 4f:a7:91:9e:8d:6f:b9:48:02:32:61:95:48:ed:1e:3f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh--id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh--id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:此处输入远程服务器主机密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.20'"
and check to make sure that only the key(s) you wanted were added.

第3步:设置服务器主机只允许密钥验证,拒绝传统口令验证方式,记得修改配置文件后保存并重启sshd服务程序哦~:
[root@linuxprobe ~]# vim /etc/ssh/sshd_config
………………省略部分输出信息………………
74
75 # To disable tunneled clear text passwords, change to no here!
76 #PasswordAuthentication yes
77 #PermitEmptyPasswords no
78 PasswordAuthentication no
79
………………省略部分输出信息………………
[root@linuxprobe ~]# systemctl restart sshd

第4步:在客户端主机尝试登陆到服务端主机,此时无需输入密码口令也可直接验证登陆成功:
[root@linuxprobe ~]# ssh 192.168.10.20
Last login: Mon Apr 13 19:

⑥ linux下怎样设置ssh无密码登录

第1步:在本地主机中生成“密钥对”并将公钥传送到远程服务器中:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):直接敲击回车或设置密钥的存储路径
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 直接敲击回车或设置密钥的密码
Enter same passphrase again: 再次敲击回车或设置密钥的密码
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
40:32:48:18:e4:ac:c0:c3:c1:ba:7c:6c:3a:a8:b5:22 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|+*..o . |
|*.o + |
|o* . |
|+ . . |
|o.. S |
|.. + |
|. = |
|E+ . |
|+.o |
+-----------------+

第2步:将生成好的私钥文件传送至远程主机:
[root@linuxprobe ~]# ssh--id 192.168.10.20
The authenticity of host '192.168.10.20 (192.168.10.20)' can't be established.
ECDSA key fingerprint is 4f:a7:91:9e:8d:6f:b9:48:02:32:61:95:48:ed:1e:3f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh--id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh--id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:此处输入远程服务器主机密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.20'"
and check to make sure that only the key(s) you wanted were added.

第3步:设置服务器主机只允许密钥验证,拒绝传统口令验证方式,记得修改配置文件后保存并重启sshd服务程序哦~:
[root@linuxprobe ~]# vim /etc/ssh/sshd_config
………………省略部分输出信息………………
74
75 # To disable tunneled clear text passwords, change to no here!
76 #PasswordAuthentication yes
77 #PermitEmptyPasswords no
78 PasswordAuthentication no
79
………………省略部分输出信息………………
[root@linuxprobe ~]# systemctl restart sshd

第4步:在客户端主机尝试登陆到服务端主机,此时无需输入密码口令也可直接验证登陆成功:
[root@linuxprobe ~]# ssh 192.168.10.20
Last login: Mon Apr 13 19:34:13 2017

ssh的话你可以详细看一下http://www.linuxprobe.com/chapter-09.html#921_sshd

⑦ linux下怎样设置ssh无密码登录

ssh 是一个专为远程登录会话和其他网络服务提供安全性的协议。默认状态下ssh链接是需要密码认证的,可以通过添加系统认证(即公钥-私钥)的修改,修改后系统间切换可以避免密码输入和ssh认证。以下将创建过程简单介绍下。

一、用ssh-keygen创建公钥
haifeng@haifeng-EX38-DS4:/$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/haifeng/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/haifeng/.ssh/id_rsa.
Your public key has been saved in /home/haifeng/.ssh/id_rsa.pub.
The key fingerprint is:
7b:75:98:eb:fd:13:ce:0f:c4:cf:2c:65:cc:73:70:53 haifeng@haifeng-EX38-DS4
The key's randomart image is:
+--[ RSA 2048]----+
| E|
| .|
| ...|
| + =.|
| S + +.*|
| . . + Bo|
| . . . = =|
| . . . * |
| . ..=|
+-----------------+

##输入后,会提示创建.ssh/id_rsa、id_rsa.pub的文件,其中第一个为密钥,第二个为公钥。过程中会要求输入密码,为了ssh访问过程无须密码,可以直接回车 。
2.查看钥匙。
[root@localhost .ssh]# ls ~/.ssh/
id_rsa id_rsa.pub known_hosts

###可以发现 ssh目录下的两枚钥匙。
3.将公钥复制到被管理机器上面
[root@localhost .ssh]# scp id_rsa.pub [email protected]:~/.ssh/authorized_keys
[email protected]'s password:
id_rsa.pub 100% 408 0.4KB/s 00:00

4.访问
# ssh 192.168.36.194
The authenticity of host '<Game2> (<192.168.36.194>)' can't be established.
RSA key fingerprint is 34:b9:92:06:53:e6:91:4d:47:92:73:57:78:6a:5d:09.
Are you sure you want to continue connecting (yes/no)?yes
Warning: Permanently added '<Game2> (<192.168.36.194>' (RSA) to the list of known hosts.

这是因为首次访问后,ssh会在.ssh/known_hosts中保存各个认证过的主机信息:
192.168.36.194 ssh-rsa +W8X8qk1CoPdzu8YcMCpw5425mai0/RxkB/+YElCgH+/8ULgaKg3LtvP+/p0ml+uuS4DO3Up2VjqoRtqtuzWExnTyAGS//YLTGF8vVvjo5w==
5.再次访问,ssh登录发现可以不用密码登录。
[root@localhost .ssh]# ssh 192.168.36.194
Last login: Fri Apr 22 00:56:45 2011 from 192.168.18.44
[root@Game2 ~]#

⑧ 如何在linux中如何配置ssh免密码登录

首先需要在服务器端设置/etc/ssh/sshd_config
# vim /etc/ssh/sshd_config
修改如下两行为yes。其实大多数情况下不用修改,默认就是yes。
RSAAuthentication yes
PubkeyAuthentication yes
(1) 如果客户机和服务器都是Linux机器,那么我们使用下面的方法:(后面第2节会提到怎么在Windows下使用Putty生成密钥对)
我们需要在客户端生成RSA密钥对。使用ssh-keygen命令:
# ssh-keygen -t rsa
参数t的意思是type,后面跟着加密类型,这里我们是rsa。
然后会提示你输入密钥保存完成文件名,这里我们需要使用默认的id_rsa,之后才能正常才能登录。如果你生成的密钥作为其他用处,那么可以命名为其他名称:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cake/.ssh/id_rsa):
之后会提示你输入一个passphrase,我们这里可以留空,这样我们登录的时候就不许输入密码。
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
然后会提示你密钥生成成功。这是你的私钥保存为~/.ssh/id_rsa,你的公钥是~/.ssh/id_rsa.pub
我们现在需要做的是,把id_rsa.pub的内容,添加的服务器端的~/.ssh/autherized_keys文件最后。
你可以把这个文件上传到服务器端,然后使用命令:
# cat id_rsa.pub >> ~/.ssh/autherized_keys
到这里就完成了。
(2) 在Windows下使用Putty生成密钥对:
Putty的安装目录下有个puttygen.exe程序,我们运行这个程序。
之后点击Generate,开始生成密钥对。我们需要根据提示,在指定方框内随机滑动鼠标。这是为了根据鼠标轨迹,产生一些随机数据。
之后生成结束,我们点击Save Private Key将私钥存放在某个目录中。然后赋值最上面文本框中的全部内容,粘贴到Linux服务器端的autherized_key的最后。
我们现在可以关闭这个小程序。
现在打开Putty,在左边的选项中,选择Conneciton–SSH–Auth,在Private key file for authentication中,选择刚才保存的私钥路径就可以了。
到此位置,Putty也可以不用密码登录了。

⑨ 怎么可以无密码ssh 访问linux

1、用ssh-keygen创建公钥
(1)在服务器1上执行下面的命令:

[plain] view plain print?
[root@Server1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key(/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in/root/.ssh/id_rsa.
Your public key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
7b:aa:08:a0:99:fc:d9:cc:d8:2e:4b:1a:c0:6b:da:e4root@Server1
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
|. |
|o. S |
|++. . |
|+=o. . . |
|o+=oB. o |
|..E==*... |
+-----------------+
输入后,会提示创建.ssh/id_rsa、id_rsa.pub的文件,其中第一个为密钥,第二个为公钥。过程中会要求输入密码,为了ssh访问过程无须密码,可以直接回车 。

(2)补充说明:
ssh-keygen:生成秘钥
其中:
-t指定算法
-f 指定生成秘钥路径
-N 指定密码

2、查看钥匙
[plain] view plain print?
[root@Server1 ~]# ls -l .ssh
总用量 8
-rw-------. 1 root root 1675 12月 10 22:20 id_rsa
-rw-r--r--. 1 root root 394 12月 10 22:20 id_rsa.pub
可以发现 ssh目录下的两枚钥匙。

3.将公钥复制到被管理机器Server2和Server3下的.ssh目录下(先确保存在这个目录)
[plain] view plain print?
[root@server1 .ssh]# scp [email protected]:~/.ssh/
The authenticity of host '192.168.1.3(192.168.1.3)' can't be established.
RSA key fingerprint is93:eb:f9:47:b1:f6:3f:b4:2e:21:c3:d5:ab:1d:ae:65.
Are you sure you want to continueconnecting (yes/no)? yes
Warning: Permanently added '192.168.1.3'(RSA) to the list of known hosts.
[email protected]'s password:
id_rsa.pub
[root@server1 .ssh]# scp [email protected]:~/.ssh/authorized_keys
The authenticity of host '192.168.1.4(192.168.1.4)' can't be established.
RSA key fingerprint is93:eb:f9:47:b1:f6:3f:b4:2e:21:c3:d5:ab:1d:ae:65.
Are you sure you want to continueconnecting (yes/no)? yes
Warning: Permanently added '192.168.1.4'(RSA) to the list of known hosts.
[email protected]'s password:
id_rsa.pub
到Server2和Server3目录下执行下面的命令

[plain] view plain print?
#cat id_dsa.pub >> ~/.ssh/authorized_keys
4、设置文件和目录权限:
设置authorized_keys权限

[plain] view plain print?
$ chmod 600 authorized_keys
设置.ssh目录权限

[plain] view plain print?
$ chmod 700 -R .ssh
5、验证使用SSH IP地址的方式无密码访问
[plain] view plain print?
[root@server1 .ssh]# ssh 192.168.1.3
Last login: Tue Dec 10 22:34:02 2013
[root@Server2 ~]#
[root@Server2 ~]#
[root@Server2 ~]#

⑩ linux下怎样设置ssh无密码登录

方法/步骤

主机A:192.168.1.110

主机B:192.168.1.111

需要配置主机A无密码登录主机A,主机B

先确保所有主机的防火墙处于关闭状态。

在主机A上执行如下:

1.$cd ~/.ssh

2.$ssh-keygen -t rsa --------------------然后一直按回车键,就会按照默认的选项将生成的密钥保存在.ssh/id_rsa文件中。

3.$cp id_rsa.pub authorized_keys

这步完成后,正常情况下就可以无密码登录本机了,即ssh localhost,无需输入密码。

4.$scp authorized_keys [email protected]:/home/hadoop/.ssh ------把刚刚产生的authorized_keys文件拷一份到主机B上.

5.$chmod 600 authorized_keys

进入主机B的.ssh目录,改变authorized_keys文件的许可权限。



正常情况下上面几步执行完成后,从主机A所在机器向主机A、主机B所在机器发起ssh连接,只有在第一次登录时需要输入密码,以后则不需要。

可能遇到的问题:

1.进行ssh登录时,出现:”Agent admitted failure to sign using the key“ .

执行: $ssh-add

强行将私钥 加进来。

2.如果无任何错误提示,可以输密码登录,但就是不能无密码登录,在被连接的主机上(如A向B发起ssh连接,则在B上)执行以下几步:

$chmod o-w ~/

$chmod 700 ~/.ssh

$chmod 600 ~/.ssh/authorized_keys

3.如果执行了第2步,还是不能无密码登录,再试试下面几个

$ps -Af | grep agent

检查ssh代理是否开启,如果有开启的话,kill掉该代理,然后执行下面,重新打开一个ssh代理,如果没有开启,直接执行下面:

$ssh-agent

还是不行的话,执行下面,重启一下ssh服务

$sudo service sshd restart

4. 执行ssh-add时提示“Could not open a connection to your authenticationh agent”而失败

执行: ssh-agent bash

热点内容
数据库分离与附加 发布:2024-05-02 20:56:59 浏览:39
搭建我的世界java服务器详细篇 发布:2024-05-02 20:56:59 浏览:941
string函数java 发布:2024-05-02 20:36:49 浏览:801
phplinux服务器 发布:2024-05-02 20:30:23 浏览:754
安卓在哪里安装网易官方手游 发布:2024-05-02 20:15:07 浏览:409
qq宠物的文件夹 发布:2024-05-02 20:13:46 浏览:366
做脚本挂 发布:2024-05-02 19:09:14 浏览:931
打王者开最高配置哪个手机好 发布:2024-05-02 19:08:31 浏览:351
python字典使用 发布:2024-05-02 19:01:14 浏览:134
我的世界服务器联机ip 发布:2024-05-02 18:50:39 浏览:619