开发者

how to ssh / su - by passing the password initially itself?

Anyone knows how to ssh / su - by passing the password initially itself?

Like:

ssh username@h开发者_JAVA百科ostname  -p [password] 
pbrun su - unix_owner -p [password] 

How can I achieve this?

It shouldn't popup for password or any RSA authentication like yes/no.


I think you will probably need a sudoers file to get stuff done in a su like manner without being prompted for a password.

I have never used ssh without a password prompt, but found this which suggests it can be done...


passing a password in clear text is not intended by ssh. Try to learn about ssh key authentication (google would help), you won't need to type your password anymore.

ok, more detailed, try this:

on the remote machine

> mkdir -p ~/.ssh  #if neccessary
> touch ~/.ssh/authorized_keys2
> chmod go-rwx $HOME/.ssh/authorized_keys2

on your local machine:

> ssh-keygen # if neccessary
> cat ~/.ssh/id_rsa.pub | ssh root@remotehost "cat >> .ssh/authorized_keys2 && chmod 0600 ~/.ssh/authorized_keys2"


A better approach would be using ssh keys, like other answers recommend, but if you really need it, you can use expect for that. Just create a expect.file like this one:

#!/usr/bin/env expect

set username youruser
set pass yourpassword
set host yourhost

spawn ssh ${username}@${host}

expect -re "password:"
send "${pass}\r"

expect -re "$"

interact

and execute it:

expect expect.file


Can't do it. You're invoking the passwd program on the remote machine. If it had a way to change a password without prompting for the old one, ANYONE could change your password if they got onto your console. You'd still need to pass the password in over the ssh link


As for SSH, you could use RSA keys, and those won't prompt you for passwords.

As for SU, it would have to be hardcoded or you would have to create your own application to serve as a wrapper of sorts.


I don't think you can pass in password directly to the ssh command (It will be stored in your history otherwise). Why don't you use keys to skip the authentication prompt.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜