“Linux命令”的版本间的差异
来自qingwei personal wiki
(→ssh) |
(→免密登入) |
||
(未显示同一用户的3个中间版本) | |||
第9行: | 第9行: | ||
# 在client端,使用pem登入 | # 在client端,使用pem登入 | ||
ssh sdn@80.8.8.21 -i key-qingwyan2.pem | ssh sdn@80.8.8.21 -i key-qingwyan2.pem | ||
+ | |||
+ | # 可以不用加 -i参数登入 | ||
+ | ssh-add key-qingwyan2.pem | ||
</source> | </source> | ||
+ | === 免密登入 === | ||
+ | <source lang="shell"> | ||
+ | # ~/.ssh 目录下有如下文件 | ||
+ | $ ls | ||
+ | authorized_keys id_rsa id_rsa.pub known_hosts | ||
+ | # authorized_keys 权限必须600, 将client公有密匙(id_rsa.pub)copy到server同用户名的~/.ssh/authorized_keys里面,就能免密登入 | ||
+ | </source> | ||
+ | |||
=== debug === | === debug === | ||
==== server端 ==== | ==== server端 ==== | ||
第68行: | 第79行: | ||
qingwyan ALL=(ALL) ALL | qingwyan ALL=(ALL) ALL | ||
</source> | </source> | ||
+ | |||
+ | [[category: linux]] |
2018年4月27日 (五) 06:41的最新版本
目录
ssh
pem登入方式
# server端 设置 authorized_keys
# 确保 authorized_keys 权限600
# 把public key 存放在这个文件下
vi /home/sdn/.ssh/authorized_keys
# 在client端,使用pem登入
ssh sdn@80.8.8.21 -i key-qingwyan2.pem
# 可以不用加 -i参数登入
ssh-add key-qingwyan2.pem
免密登入
# ~/.ssh 目录下有如下文件
$ ls
authorized_keys id_rsa id_rsa.pub known_hosts
# authorized_keys 权限必须600, 将client公有密匙(id_rsa.pub)copy到server同用户名的~/.ssh/authorized_keys里面,就能免密登入
debug
server端
# vi /etc/ssh/sshd_conf
LogLevel DEBUG3
# restart sshd
service sshd restart
# 查看log
tail -f /var/log/secure
client端
# -v debug1级别
# -vvv debug3级别
ssh -vvv sdn@80.8.8.21 -i key-qingwyan2.pem
cmd
sshpass
# 第一次必须ssh登入一次
sshpass -p cisco123 ssh root@192.168.125.186
awk
打印第一行第二列
ps -ef | grep sshd | head -n1 | awk {'print $2'}
# example
[qingwyan@localhost smartphy114]$ ps -ef | grep sshd
root 1405 1 0 Nov23 ? 00:00:00 /usr/sbin/sshd -D
root 13092 1405 0 19:49 ? 00:00:00 sshd: qingwyan [priv]
qingwyan 13108 13092 0 19:49 ? 00:00:00 sshd: qingwyan@notty
qingwyan 16602 32280 0 21:07 pts/5 00:00:00 grep --color=auto sshd
root 20010 1405 0 Nov28 ? 00:00:02 sshd: root@pts/19
[qingwyan@localhost smartphy114]$ ps -ef | grep sshd | head -n1 | awk {'print $2'}
1405
sed
替换文本里所有符合条件字符
sed -i 's/原来字符/替换字符/g' "替换的文件名"
用户管理
添加sudo权限用户
adduser username
passwd username
usermod -aG wheel username
# 修改文件 /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
qingwyan ALL=(ALL) ALL