Linux命令-设置免密码登录
设置免密码登陆:
[root@Redis01 test]# cd /install/
[root@Redis01 install]# rm -rf test/
[root@Redis01 install]# ls
initNetwork.sh
[root@Redis01 install]# ssh Redis02
root@redis02's password:
Last login: Thu Nov 30 23:28:06 2017 from 192.168.238.1
[root@Redis02 ~]# ls /software/
jdk1.7.0_79 mysql-5.5.32 redis-2.8.9
[root@Redis02 ~]# exit
logout
Connection to Redis02 closed.
[root@Redis01 install]# ssh Redis02 "ls /software"
root@redis02's password:
jdk1.7.0_79
mysql-5.5.32
redis-2.8.9
在Redis01设置加密协议:(此处按了三次Enter)
[root@Redis01 install]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
4f:a4:b0:91:3b:75:18:22:9b:f3:f9:11:e4:c6:8d:fb root@Redis01
The key's randomart image is:
+--[ RSA 2048]----+
| . . o |
| + * = |
| + + O + |
| o O * |
| * S . |
| o = |
| . E |
| |
| |
+-----------------+
将加密协议复制到Redis02:
[root@Redis01 install]# ssh-copy-id Redis02
root@redis02's password:
Now try logging into the machine, with "ssh 'Redis02'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
此时在Redis01中登陆Redis02将不需要密码:
[root@Redis01 install]# ssh Redis02
Last login: Thu Nov 30 23:30:44 2017 from redis01
[root@Redis02 ~]# exit
logout
Connection to Redis02 closed.
Redis01登陆自己时也需要密码,所以也需要将加密协议复制给自己:
[root@Redis01 install]# ssh Redis01
The authenticity of host 'redis01 (192.168.238.128)' can't be established.
RSA key fingerprint is 82:72:60:05:6d:dc:3e:bf:f7:aa:2d:f5:08:c1:59:3a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'redis01,192.168.238.128' (RSA) to the list of known hosts.
root@redis01's password:
Last login: Thu Nov 30 15:47:03 2017 from 192.168.238.1
[root@Redis01 ~]# exit
logout
Connection to Redis01 closed.
[root@Redis01 install]# ssh-copy-id Redis01
root@redis01's password:
Now try logging into the machine, with "ssh 'Redis01'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
此时在Redis01中登陆Redis01将不需要密码:
[root@Redis01 install]# ssh Redis01
Last login: Thu Nov 30 15:58:51 2017 from redis01
[root@Redis01 ~]# exit
logout
Connection to Redis01 closed.
此时在用ssh命令时可以直接输入对应的在主机中需要执行的命令:
[root@Redis01 install]# ssh Redis02 "ls /software"
jdk1.7.0_79
mysql-5.5.32
redis-2.8.9
添加用户:
md表示设置指定用户家目录:
[root@Redis01 install]# useradd -md /home/ligang/ ligang
不可修改的查看刚添加的用户目录:
[root@Redis01 install]# less /etc/passwd
查看sh所在位置:
[root@Redis01 install]# type sh
sh is /bin/sh
[root@Redis01 install]# ls -ld /bin/s
sed setfont setserial sh sleep sort stty su sync
[root@Redis01 install]# ls -ld /bin/sh
lrwxrwxrwx. 1 root root 4 7月 13 21:25 /bin/sh -> bash
[root@Redis01 install]# type bash
bash is /bin/bash
[root@Redis01 install]# grep ligang /etc/passwd
ligang:x:502:502::/home/ligang/:/bin/bash
设置用户ligang的密码,必须设置密码才能登陆:
[root@Redis01 install]# passwd ligang
更改用户 ligang 的密码 。
新的 密码:
无效的密码: 它基于字典单词
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
不可修改的查看刚添加的用户的密码:
[root@Redis01 install]# less /etc/shadow
sh默认有权限;./没有权限;
[root@Redis01 test]# ./a.sh
-bash: ./a.sh: 权限不够
[root@Redis01 test]# sh a.sh
Hello World
[root@Redis01 ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc install.log .mysql_history .ssh .viminfo
.. .bash_history .bash_profile .cshrc install.log.syslog .rediscli_history .tcshrc
.当前目录;..上一级目录;.开头的文件表示隐藏文件;
[root@Redis01 ~]# ll -a
总用量 96
dr-xr-x---. 3 root root 4096 11月 29 22:20 .
dr-xr-xr-x. 24 root root 4096 12月 1 10:35 ..
-rw-------. 1 root root 1311 7月 13 21:33 anaconda-ks.cfg
-rw-------. 1 root root 9570 12月 1 10:34 .bash_history
-rw-r--r--. 1 root root 18 5月 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 5月 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 9月 23 2004 .bashrc
-rw-r--r--. 1 root root 100 9月 23 2004 .cshrc
-rw-r--r--. 1 root root 22618 7月 13 21:33 install.log
-rw-r--r--. 1 root root 5890 7月 13 21:32 install.log.syslog
-rw-------. 1 root root 452 11月 28 23:43 .mysql_history
-rw-r--r--. 1 root root 197 11月 30 00:04 .rediscli_history
drwx------. 2 root root 4096 11月 30 15:59 .ssh
-rw-r--r--. 1 root root 129 12月 4 2004 .tcshrc
-rw-------. 1 root root 686 11月 28 00:35 .viminfo
.ssh中的authorized_keys和known_hosts负责保存加密协议;
删除这两个文件后,再次通过ssh协议连接时需要输入密码;
[root@Redis01 ~]# cd .ssh/
[root@Redis01 .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
清空的意思,相当于空覆盖原有内容:
[root@Redis01 .ssh]# >known_hosts
[root@Redis01 .ssh]# >authorized_keys
[root@Redis01 .ssh]# ls -ld authorized_keys
-rw-------. 1 root root 394 11月 30 15:59 authorized_keys
[root@Redis01 ~]# ls -ld .ssh
drwx------. 2 root root 4096 11月 30 15:59 .ssh
Linux命令-设置免密码登录的更多相关文章
- Linux 配置ssh 免密码登录
在平常应用中,我们经常会登录到其他主机,比如说服务器,每次都需要用户名和密码. 我们可以通过ssh免密码登录服务器而不需要输入密码. 现在有一台ubuntu的阿里云服务器,称之为 server. 公 ...
- linux实现ssh免密码登录
linux实现ssh免密码登录 本地系统执行 ssh-keygen -t rsa 命令,生成密钥文件 在相应的目录下查看生成的密钥文件,其中:id_rsa为私钥文件,id_rsa.pub为公钥文件 本 ...
- Linux下SSH免密码登录
转自:http://haitao.iteye.com/blog/1744272 ssh配置 主机A:10.0.5.199 主机B:10.0.5.198 需要配置主机A无密码登录主机A,主机B 先确保所 ...
- linux ssh公钥免密码登录
ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 一.SSH公钥登录原理 在平时工作中我们经常要远程登录服务器,这就要用到SSH ...
- linux 配置ssh免密码登录
1.确保主机名唯一 主机名修改方法: a.修改/etc/sysconfig/network,HOSTNAME=想要设置的主机名称 b.修改/etc/hosts,127.0.0.1 localhos ...
- linux操作系统-两台linux服务器SSH免密码登录
A为本地主机(即用于控制其他主机的机器) ; B为远程主机(即被控制的机器Server), ip为192.168.100.247 ; A和B的系统都是Linux 在A上的命令 # ssh-keyg ...
- git设置免密码登录
设置用户名和邮箱 git config --global user.name "<username>" git config --global user.email & ...
- jenkins发布项目到远程主机上,配置linux使用SSH免密码登录
一.首先要配置两台linux如何使用SSH免密码登录,这样脚本执行scp命令以及远程执行脚本都不需要输入密码: A为本地主机(即用于控制其他主机的机器,jenkins服务器) ; B为远程主机(即被控 ...
- Mac下到Linux主机ssh免密码登录
最近忙得忘乎所以,写篇博客放松放松,RT,直接上命令好了 # Local ssh-keygen -t rsa scp ~/.ssh/id_rsa.pub username@server:~/.ssh/ ...
随机推荐
- Java类更改常量后编译不生效
在Java文件中,指向编译时static final的静态常量, 会被在运行时解析为一个局部的常量值(也就是说静态常量在编译后,成为了常量,而不是原先的代码).这对所有的基础数据类型(就像int ,f ...
- Jquery 在子页面上设置父页面元素的值
使用情景:因为我父页面上有用art.dialog,而子页面上有项目中的框架弹出方法跟art.dialog冲突,不能使用art.dialog自带的方法传值, 所以只好用一种简单粗暴的方法来设置. var ...
- 手机端-万种bt在线观看器,安卓正版下载!
安卓正版下载, 点击下载 无广告,完全免费!寻找任何你想要的资源!
- one-to-one 一对一映射关系(转 wq群)
2.配置对应的xml配置文件 person的配置文件 idCard的配置文件 idCard的配置文件 3.测试 运行测试程序后,控制台输出两条语句
- Spring使用Autowiring自动装配 解决提示报错小技巧
1.打开Settings 输入Inspections 找到Spring --> Spring Core --> Code --> Autowiring for Bean ...
- Lombok轮子
前提 自从进公司实习后,项目代码中能用 Lombok 的都用了,毕竟这么好的轮子要充分利用好.也可以减少一些 get/set/toString 方法的编写,虽说 IDEA 的插件可以自动生成 get/ ...
- 【转】在Linux下安装python3
原文链接:http://www.cnblogs.com/feng18/p/5854912.html 1.linux下安装python3 a. 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wg ...
- 恢复oracle数据从delete
今天维护系统的时候没仔细看,误删了50行数据,然后想起来以前学过delete语句删除的数据是可以回复的,但是那个时候比较慌乱,也没有心情仔细看,反而是想到了一个歪招解决了问题,我有个良好的嗜好就是经常 ...
- CDN随笔
CDN的理解:(1)CDN (内容分发网络)加速用户获取数据的 系统(2)部署在离用户最近的网络节点上(3)命中CDN 不需要访问后端服务器(4)互联网公司自己搭建或租用
- MFC对话框和属性表
对话框主要有两类,分为模式和无模式,它们的功能都被封装在了CDialog中.与对话框相近的是属性表,属性表实际上是具有制表页(TAB 页)的对话框,将对话框中控件更好的组织在一起.借助Cpropert ...