vmvz / a

wiki
2 stars 0 forks source link

centos add key #41

Open vmvz opened 6 years ago

vmvz commented 6 years ago
#!/bin/sh

SSHHOME="$HOME/.ssh"
AUTHKEY="$HOME/.ssh/authorized_keys"

#create HOME/.ssh dir if not existed
if [ ! -d $SSHHOME ]; then
    mkdir -p -m 700 $SSHHOME;
fi

#add new line to the end if not present
if [ -f $AUTHKEY ]; then
    if [ "$(tail -c 1 $AUTHKEY)" != "" ]; then
        echo "" >> $AUTHKEY;
    fi
fi

#add ssh pub key
cat >> $AUTHKEY << EOF
sh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXMUp7qdgeHCRp+xUWMoKLko+6pD1fUjRqU303z+fCGX4EM7iN3dIFHQHRHq/o74FFKBF0Z+IW48LNl9fM1krdvgrPqYCYigXr5tzBsYBYA0CthaV1VjlfjJU+9CFiWbqlkc98oHHK3SWhEaWpZTnI7jcc6VuEMg0/mDYVTZcETHKBoakzrDV0TePkQ9pfTxnDCyFZVe8KVnyMwhbD1YOpIoVALLpkTtgna+Y9W7ir3bbvVWD9aGjp8AMxhyZ3jzuKK0uQydG3pMVYbxNIqIW9M61/0a7AKc7Q0e2ieYYMb2bV9YE4nrH4shAU4zPrbhEXx/LRgbg5Dfe0i7SEZcPD d@d-p410.local
EOF

#check secure mod
if [ "$(stat -c '%a' $AUTHKEY)" != "600" ]; then
    chmod 600 $AUTHKEY;
fi

if command -v selinuxenabled && selinuxenabled; then
    restorecon -R -v $SSHHOME
fi

echo "Done Adding Keys. -- by Preston M."
exit 0;
vmvz commented 6 years ago

https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-centos7

vmvz commented 6 years ago

DNS

解决方案二(推荐):

对接口添加dns信息;编辑/etc/sysconfig/network-scripts/ifcfg-ethX,x可能是其他数字,但一般是ifcfg-eth0的,具体的X根据你的网卡确定,在最下面添加: DNS1=8.8.8.8 #google dns服务器, 根据实际情况更换 DNS2=8.8.4.4 #google dns服务器, 根据实际情况更换 保存后重启网络 service network restart