Bash Script - Moving to KKE

Hi,
Something is wrong with this scenario. I made script that passwordless copy zipped directory form stapp03 to backup server. I checked if it copied right, and still got failed.

root@stapp03 scripts]# ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XPHlScAFcL0ymluDqV/+tjV8mfZGLb5E2moKo5XQ7iM root@stapp03
The key’s randomart image is:
±–[RSA 2048]----+
| oo+=+ |
| +.+… |
| . . o. |
| o . o . |
| . S = o. .|
| o .= o+o =|
| *. ooooOo|
| E+oo.o.o+.=|
| …ooooo++.|
±—[SHA256]-----+
[root@stapp03 scripts]# ssh-copy-id clint@stbkp01
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_rsa.pub”
The authenticity of host ‘stbkp01 (172.16.238.16)’ can’t be established.
ECDSA key fingerprint is SHA256:CgV5OvTrQuqVlZyah+PDsjjVlQEG1I5hyuyNhDy+Iio.
ECDSA key fingerprint is MD5:15:f0:cc:60:e0:43:3e:ed:e6:d3:3a:be:03:e2:64:96.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
clint@stbkp01’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘clint@stbkp01’”
and check to make sure that only the key(s) you wanted were added.

[root@stapp03 scripts]# vi news_backup.sh
[root@stapp03 scripts]# ./news_backup.sh
adding: var/www/html/news/ (stored 0%)
adding: var/www/html/news/.gitkeep (stored 0%)
adding: var/www/html/news/index.html (stored 0%)
xfusioncorp_news.zip 100% 588 1.2MB/s 00:00
[root@stapp03 scripts]# ls -al
total 12
drwxrwxrwx 2 root root 4096 May 20 13:15 .
drwxr-xr-x 1 root root 4096 May 20 13:10 …
-rwxr-x— 1 root root 127 May 20 13:15 news_backup.sh
[root@stapp03 scripts]# ssh ^C
[root@stapp03 scripts]# ssh clint@stbkp01
[clint@stbkp01 ~] ls /backup/ xfusioncorp_news.zip [clint@stbkp01 ~] exit
logout
Connection to stbkp01 closed.
[root@stapp03 scripts]# ./news_backup.sh
updating: var/www/html/news/ (stored 0%)
updating: var/www/html/news/.gitkeep (stored 0%)
updating: var/www/html/news/index.html (stored 0%)
xfusioncorp_news.zip 100% 588 958.8KB/s 00:00
[root@stapp03 scripts]# ls -al
total 12
drwxrwxrwx 2 root root 4096 May 20 13:15 .
drwxr-xr-x 1 root root 4096 May 20 13:10 …
-rwxr-x— 1 root root 127 May 20 13:15 news_backup.sh
[root@stapp03 scripts]# ls /backup/
xfusioncorp_news.zip
[root@stapp03 scripts]# ls -al /backup/
total 12
drwxrwxrwx 2 root root 4096 May 20 13:15 .
drwxr-xr-x 1 root root 4096 May 20 13:10 …
-rw-r–r-- 1 root root 588 May 20 13:15 xfusioncorp_news.zip
thor@jump_host /$

1 Like

the error you made is while you were trying to setup the passwordless as the cmd bellow show us
“root@stapp03 scripts]# ssh-copy-id clint@stbkp01”
you must to setup passwordless for the active user in stapp03 which is Banner user, so you need to run the same command using banner user such as
“banner@stapp03 # sudo ssh-copy-id clint@stbkp01” that way you will create a key and setup passwordless for banner user and not for root

HI, i don’t understand, why us create password-less for banner@stapp03. As i know the question request copy the file on BACKUP from stapp03 to backup server. So that, we need scp form stapp03 to stbkp01. This mean with the ssh without password we need create ssh-key-gen in the stapp03 and copy .pub of stapp03 to stbkp01.
Please let me know if i understand wrong the question