Different machines must not root login with remote. All machines at user ygh_ssh(ordinary user).shell
NFS_SERVICE send data and NFS_CLIENT_1, NFS_CLIENT_2 receive data. Don’t be asked password when send or receive data.ssh
Three Linux System machines, ant they can ping each.ide
we use SSH to transmission data, because SSH can make sure safe with SSH2.xui
Hostnamethis |
Network cardspa |
Gateway3d |
Functionsblog |
NFS_SERVICEthree |
192.168.98.132ip |
255.255.255.0 |
Center sender |
NFS_CLIENT_1 |
192.168.98.131 |
255.255.255.0 |
Receiver |
NFS_CLIENT_2 |
192.168.98.134 |
255.255.255.0 |
Receiver |
Three Linux System all use the user name is 「ygh_ssh」 and uid=」666」 to transmission data.
The need is NFS_SERVICE can send data to NFS_CLIENT_1 and NFS_CLIENT_2, so private key is in NFS_SERVICE and public key is in NFS_CLIENT_1, NFS_CLIENT_2.
Firstly, we make three Linux login 「ygh_ssh」.
Secondly, we use 「ssh-keygen -t dsa」 command to create private key and public key.
you can give password, but you can also press 「Enter」 until end.
-t sda indicates use 「sda」 algorithem.
In 「ygh_ssh」 home directory, you will find a 「.ssh」 hidden directory
The this directory, we will viem three main file:
id_dsa:private key
id_dsa_pub:public key
Others file you can ingore if you haven’t
So we shoud keep private to local and send public to service(NFS_CLIENT_1, NFS_CLIENT_2.
).
we use this command 「ssh-copy-id [-i [identity_file]] [user@]machine」 to send public key to Service.
for example:
use follow commands to send public key to NFS_CLIENT_1
ssh-copy-id -i /home/ygh_ssh/.ssh/id_dsa.pub "-p 52113 ygh_ssh@192.168.98.131"
You should give ygh_ssh@192.168.98.131 password for the first time connection.
If you repeat above actions, you will find it’s needn’t password.
You also use this command to test whether you public key received. Using this command
「ssh -p 52113 ygh_ssh@192.168.98.131」 ,then you find you don’t give password and connect the NFS_CLIENT_1(you hostname change to NFS_CLIENT_1), it indelicate you success.
we need to send public key to NSF_CLIENT_2 repeat above actions.
In NFS_CLIENT_1 or NFS_CLIENT_2 /home/ygh_ssh/.ssh/
you will view a file named 「authorized_keys」, it is public key. It is same as the file id_dsa_qub at NFS_SERVICE /home/ygh_ssh/.ssh
Now we can transmit date use NSF_SERVICE with NFS-CLIENT_2 and NFS_CLIENT_1 withput password!
Firstly, we should write a shell scripts to help us send batch file.t
# batch send file script author:ygh date:2017-01-09
#file="$1"
. /etc/init.d/functions
for n in 131 134 123 122
do
scp -P52113 -rp $1 ygh_ssh@192.168.98.$n:~
done
In NFS_CLIENT_1 or NFS_CLIENT_2 /home/ygh_ssh/ you will find /data
This indelicate data transmission success.
We know, we use ygh_ssh only can write data to some directories that it is permitted, but if we want to transmit data to /root or /ect. How to do
we you use this thoughts:
一、 cp file or directory to ygh_ssh home directory
二、 mv this file to the directory that you want set.
三、 give ygh_ssh 「sudo mv source file desDirectory」.
In NFS_CLINET_1 or NFS_CLINET_2 to give sudo mv authority to ygh_ssh
Use follow shell scripts:
# batch send file script author:ygh date:2017-01-09
file="$1"
remotedir="$2"
. /etc/init.d/functions
for n in 131 134 123 122
do
scp -P52113 -rp $1 ygh_ssh@192.168.98.$n:~ > /dev/null 2>&1 &&\
ssh -t -p 52113 ygh_ssh@192.168.98.$n "sudo /bin/mv ~/$file $remotedir" > /dev/null 2>&1
if [ $? -eq 0 ]
then
action "scp $file to ygh_ssh@192.168.98.$n:$remotedir is ok" /bin/true
else
action "scp $file to ygh_ssh@192.168.98.$n:$remotedir is failed" /bin/false
fi
done
In NSF_CLIENT_1 or NFS_CLIENT_2 /root, you will view
一、 It is single forward only from NFS_SERVICE to NFS_CLIENT_2 , NFS_CLIENT_1
二、 It is based users, you better don’t span users
三、 If you SSH connection is slow, you can retrieve following: