添加公钥
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
name="$(whoami)"
path="$(getent passwd | cut -d: -f6 | grep $name)"
echo $path
# 当前用户的公钥的路径
rsaPub="${path}/.ssh/id_rsa.pub"
pubContent="$(cat $rsaPub)"
# https://superuser.com/questions/400714/how-to-remotely-write-to-a-file-using-ssh
echo $pubContent | ssh root@$1 -T "cat >> /root/.ssh/authorized_keys"
# TODO how to pretend to write multiple keys to remote server.
ssh root@$1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
name="$(whoami)"
path="$(getent passwd | cut -d: -f6 | grep $name)"
echo $path
# 当前用户的公钥的路径
rsaPub="${path}/.ssh/id_rsa.pub"
pubContent="$(cat $rsaPub)"
# https://superuser.com/questions/400714/how-to-remotely-write-to-a-file-using-ssh
echo $pubContent | ssh root@$1 -T "cat >> /root/.ssh/authorized_keys"
# TODO how to pretend to write multiple keys to remote server.
ssh root@$1
复制成功
This post is licensed under CC BY 4.0 by the author.