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

linuxssh免密

发布时间: 2022-04-19 11:47:34

linux ssh免密码登录必须在root下操作吗

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无密码登录

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

❸ linux怎么删除ssh 免密码登陆

找到authorized_keys 文件 (例如/root/.ssh/authorized_keys)
假如 有 A、B、C 三台服务器
如果不想让A免密登录B ,那么修改B服务器的authorized_keys ,将有A的ip或hostname的那行记录注释掉
同理如果都不想免密,把三台服务器的authorized_keys文件,内容都注释就OK了

❹ linux系统,多台机器ssh免密码登录同一台机器执行某个脚本,不需要expect

A B C三台机器上以当前用户运行如下命令生成本主机的公钥和私钥文件:

ssh-keygen-trsa

上述命令执行后,目录~/.ssh下会出现两个文件:id_rsa和id_rsa.pub。其中,id_rsa.pub为公钥文件。将该文件的内容追加到主机D上~/.ssh目录下的authorized_keys文件中。例如:

A机将id_rsa.pub文件传到D机:

scp~/.ssh/id_rsa.pubuser@HOSTD:/tmp/id_rsa_HOSTA.pub

D机user用户追加authorized_keys文件:

cat/tmp/id_rsa_HOSTA.pub>>~/.ssh/authorized_keys

接下来,就可以在不输入密码的情况下在远程主机私执行命令了。命令格式如下:

ssh 远程用户名@远程主机名或IP地址 '远程命令或者脚本'

例如:

sshuser@HOSTD'hostname'
sshuser@HOSTD'/home/user/script/test.sh'

需要特别注意的是:当远程脚本中使用了一些命令识别依赖于环境变量时,该脚本需要在其第一行中包含执行profile文件的命令。比如,在Bash中,该脚本的第一行为:

source~/.bash_profile

否则,远程脚本可能报错。

❺ linux如何配置双机SSH信任然后双向免密码登陆

一、实现原理
使用一种被称为"公私钥"认证的方式来进行ssh登录。"公私钥"认证方式简单的解释是:
首先在客户端上创建一对公私钥(公钥文件:~/.ssh/id_rsa.pub;私钥文件:~/.ssh/id_rsa),然后把公钥放到服务器上(~/.ssh/authorized_keys),自己保留好私钥。当ssh登录时,ssh程序会发送私钥去和服务器上的公钥做匹配。如果匹配成功就可以登录了。
二、实验环境
A机:TS-DEV/10.0.0.163
B机:CS-DEV/10.0.0.188
三、Linux/Unix双机建立信任
3.1
在A机生成证书
在A机root用户下执行ssh-keygen命令,在需要输入的地方,直接回车,生成建立安全信任关系的证书。
#
ssh-keygen
-t
rsa
注意:在程序提示输入passphrase时直接输入回车,表示无证书密码。
上述命令将生成私钥证书id_rsa和公钥证书id_rsa.pub,存放在用户家目录的.ssh子目录中。
3.2
查看~/.ssh生成密钥的文件
#
cd
~/.ssh
#
ll
3.3
A对B建立信任关系
将公钥证书id_rsa.pub复制到机器B的root家目录的.ssh子目录中,同时将文件名更换为authorized_keys,此时需要输入B机的root用户密码(还未建立信任关系)。建立了客户端到服务器端的信任关系后,客户端就可以不用再输入密码,就可以从服务器端拷贝数据了。
#
scp
-r
id_rsa.pub
10.0.0.188:/root/.ssh/authorized_keys
3.4
B对A建立信任关系
在B机上执行同样的操作,建立B对A的信任关系。
#
ssh-keygen
-t
rsa
#
cd
~/.ssh/
#
ll
#
scp
-r
id_rsa.pub
10.0.0.163:/root/.ssh/authorized_keys
如果想让B,C同时可以scp不输入密码,传输A中的数据;
则要把B、C的公钥都给
A;
操作步骤:把两机器的id_rsa.pub中的数据都拷贝到A的/root/.ssh/authorized_keys文件中,一行表示一条;
A:
scp
-r
id_rsa.pub
10.0.0.163:/root/.ssh/authorized_keys
B:
scp
-r
id_rsa.pub
10.0.0.188:/root/.ssh/authorized_keys
测试
ssh
[email protected]
'hostname'
///
ssh
[email protected]
'hostname'
如果连接反应慢,请修改以下两参数
/etc/ssh/sshd_config
GSSAPIAuthentication
no
UseDNS
no
然后重启service
sshd
restart

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

1.Linux下生成密钥
ssh-keygen的命令手册,通过”man ssh-keygen“命令:

通过命令”ssh-keygen -t rsa“

生成之后会在用户的根目录生成一个 “.ssh”的文件夹

进入“.ssh”会生成以下几个文件

authorized_keys:存放远程免密登录的公钥,主要通过这个文件记录多台机器的公钥
id_rsa : 生成的私钥文件
id_rsa.pub :生成的公钥文件
know_hosts : 已知的主机公钥清单
如果希望ssh公钥生效需满足至少下面两个条件:
1) .ssh目录的权限必须是700
2) .ssh/authorized_keys文件权限必须是600
2.远程免密登录
原理图:

常用以下几种方法:
2.1 通过ssh--id的方式
命令: ssh--id -i ~/.ssh/id_rsa.put <romte_ip>
举例:
[root@test .ssh]# ssh--id -i ~/.ssh/id_rsa.pub 192.168.91.135
[email protected]'s password:
Now try logging into the machine, with "ssh '192.168.91.135'", andcheck in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@test .ssh]# ssh [email protected]
Last login: Mon Oct 10 01:25:49 2016 from 192.168.91.133
[root@localhost ~]#
常见错误:
[root@test ~]# ssh--id -i~/.ssh/id_rsa.pub 192.168.91.135
-bash: ssh--id: command not found //提示命令不存在
解决办法:yum -y installopenssh-clients

2.2通过scp将内容写到对方的文件中
命令:scp -p~/.ssh/id_rsa.pub root@<remote_ip>:/root/.ssh/authorized_keys
举例:
[root@test .ssh]# scp -p ~/.ssh/[email protected]:/root/.ssh/authorized_keys
[email protected]'s password:
id_rsa.pub 100% 408 0.4KB/s 00:00
[root@test .ssh]#
[root@test .ssh]#
[root@test .ssh]#
[root@test .ssh]# ssh [email protected]
Last login: Mon Oct 10 01:27:02 2016 from 192.168.91.133

[root@localhost ~]#

也可以分为两步操作:
$ scp ~/.ssh/id_rsa.pubroot@<remote_ip>:pub_key //将文件拷贝至远程服务器
$ cat ~/pub_key>>~/.ssh/authorized_keys //将内容追加到authorized_keys文件中,不过要登录远程服务器来执行这条命令
2.3 通过Ansible实现批量免密
2.3.1 将需要做免密操作的机器hosts添加到/etc/ansible/hosts下:
[Avoid close]
192.168.91.132
192.168.91.133
192.168.91.134

2.3.2 执行命令进行免密操作

ansible<groupname> -m authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub') }}'" -k

示例:
[root@test sshpass-1.05]# ansible test -m authorized_key -a"user=root key='{{ lookup('file','/root/.ssh/id_rsa.pub') }}'" -k
SSH password: ----->输入密码
192.168.91.135 | success >> {
"changed": true,
"key": "ssh-rsa 7A3izwT3///18B6FV5moE/8yTbFA4dBQahdtVP +sODbtGPC34HMGAHjFlsC/SJffLuT/ug/== [email protected]",
"key_options": null,
"keyfile": "/root/.ssh/authorized_keys",
"manage_dir": true,
"path": null,
"state": "present",
"unique": false,
"user": "root"
}
[root@test sshpass-1.05]#

2.4 手工复制粘贴的方式

将本地id_rsa.pub文件的内容拷贝至远程服务器的~/.ssh/authorized_keys文件中

❼ 如何通过linux ssh远程linux不用输入密码登入

可使用SSH免密码登录,假设现在有两台机器hadoop@wang-PC(192.168.10.100),作为A机,hadoop@chen-PC(192.168.10.107),作为B机。现想hadoop@wang-PC通过ssh免密码登录到hadoop@chen-PC。
1.在A机下生成公钥/私钥对。

[hadoop@wang-PC ~]$ ssh-keygen -t rsa -P ''

敲击回车键即可,
它在/home/hadoop下生成.ssh目录,.ssh下有id_rsa和id_rsa.pub。
2.把A机器下的id_rsa.pub复制到B机器下的.ssh/authorized_keys文件里。

[hadoop@wang-PC ~]$ scp .ssh/id_rsa.pub [email protected]:/home/hadoop/id_rsa.pub.hadoop_wang
[email protected]'s password:

由于还没有免密码登录的,所以要输入密码。
3.B机把从A机复制的id_rsa.pub.hadoop_wang添加到.ssh/authorzied_keys文件里。

[hadoop@chen-PC ~]$ cat id_rsa.pub.hadoop_wang >> .ssh/authorized_keys
[hadoop@chen-PC ~]$ chmod 600 .ssh/authorized_keys

authorized_keys的权限要是600。
4.A机登录B机。

[hadoop@wang-PC ~]$ ssh 192.168.10.107

第一次登录是时要你输入yes。
现在A机可以无密码登录B机了。

小结:登录的机子可有私钥,被登录的机子要有登录机子的公钥。这个公钥/私钥对一般在私钥宿主机产生。上面是用rsa算法的公钥/私钥对,当然也可以用dsa(对应的文件是id_dsa,id_dsa.pub)
想让A,B机无密码互登录,那B机以上面同样的方式配置即可,把B的公钥复制过去添加到authorized_keys的末尾就行了。
至此完毕。

❽ 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 ~]#

热点内容
navicat导入sql失败 发布:2024-09-30 17:09:29 浏览:313
医院用电脑要什么配置 发布:2024-09-30 17:08:51 浏览:569
vs怎么与数据库连接 发布:2024-09-30 17:08:47 浏览:167
如何在虚拟机里运行脚本 发布:2024-09-30 16:54:34 浏览:627
安卓录屏怎么录内置声音不录屏 发布:2024-09-30 16:33:56 浏览:869
瑞萨编译软件安装时显示找不到 发布:2024-09-30 16:29:32 浏览:727
c语言怎么用编译器打印边框 发布:2024-09-30 16:28:04 浏览:975
图论算法的应用 发布:2024-09-30 15:50:34 浏览:944
道家算法 发布:2024-09-30 15:46:53 浏览:310
优酷下载电影存储 发布:2024-09-30 15:44:18 浏览:695