普通用户无密码登陆(运维面试题)

在A机器建立账户x,在B机器建立账户y,实现用x账户无密码登陆y账户

(做练习都是root账号,用普通账户之间的ssh无非就是拷公钥的时候,加个账户,跟用root没什么区别)

命令行实现

比如:对面账户叫做tom是有密码的。

 我自己的机器有个kitty,它也是有密码。

平时都是这样登录

  无密码登录就是做公钥私钥,

在kitty账户下,做

 做完之后,把密钥拷过去

 拷完之后再ssh就不需要密码了。

 用脚本免密登录

useradd x

cat >> /aa.sh <<-QWE

/usr/bin/expect <<-eof

spawn ssh-copy-id -i [email protected]

expect {

    "yes/no" { send "yes\n"; exp_continue }

    "password" { send "1\n" }

   }

expect eof

eof

QWE

chmod 777 /aa.sh 

/usr/bin/expect <<-eof

spawn ssh [email protected] 

expect {

    "yes/no" { send "yes\n"; exp_continue }

    "password" { send "1\n" }

   }

expect "root"

send "useradd y\n"

expect "root"

send "echo 1 | passwd --stdin y\n"

expect eof

eof

/usr/bin/expect <<-eof

set timeout 20

spawn su - x

expect "$"

send "ssh-keygen\n"

expect "id_rsa"

send "\n"

expect "pass"

send "\n"

expect "again"

send "\n"

expect eof

eof

/usr/bin/expect <<-eof

set timeout 20

spawn su - x

expect "$"

send "bash /aa.sh\n"

expect eof

eof

【注意】少熬夜,多看书。

猜你喜欢

转载自blog.csdn.net/weixin_53150440/article/details/127602423
今日推荐